Tests: Add test to check shared-memory FD leaks after relayd dies
[lttng-tools.git] / include / lttng / userspace-probe-internal.hpp
1 /*
2 * Copyright (C) 2017 Jérémie Galarneau <jeremie.galarneau@efficios.com>
3 * Copyright (C) 2018 Francis Deslauriers <francis.deslauriers@efficios.com>
4 *
5 * SPDX-License-Identifier: LGPL-2.1-only
6 *
7 */
8
9 #ifndef LTTNG_USERSPACE_PROBE_INTERNAL_H
10 #define LTTNG_USERSPACE_PROBE_INTERNAL_H
11
12 #include <common/fd-handle.hpp>
13 #include <common/macros.hpp>
14
15 #include <lttng/lttng-error.h>
16 #include <lttng/userspace-probe.h>
17
18 #include <stdbool.h>
19
20 struct lttng_payload;
21 struct lttng_payload_view;
22 struct lttng_dynamic_buffer;
23 struct mi_writer;
24
25 using userspace_probe_location_equal_cb = bool (*)(const struct lttng_userspace_probe_location *,
26 const struct lttng_userspace_probe_location *);
27 using userspace_probe_location_hash_cb =
28 unsigned long (*)(const struct lttng_userspace_probe_location *);
29 using userspace_probe_location_mi =
30 enum lttng_error_code (*)(const struct lttng_userspace_probe_location *, struct mi_writer);
31
32 /*
33 * No elf-specific comm structure is defined since no elf-specific payload is
34 * currently needed.
35 */
36 struct lttng_userspace_probe_location_lookup_method_comm {
37 /* enum lttng_userspace_probe_location_lookup_method_type */
38 int8_t type;
39 /* type-specific payload */
40 char payload[];
41 };
42
43 /* Common ancestor of all userspace probe location lookup methods. */
44 struct lttng_userspace_probe_location_lookup_method {
45 enum lttng_userspace_probe_location_lookup_method_type type;
46 };
47
48 struct lttng_userspace_probe_location_lookup_method_elf {
49 struct lttng_userspace_probe_location_lookup_method parent;
50 };
51
52 struct lttng_userspace_probe_location_lookup_method_sdt {
53 struct lttng_userspace_probe_location_lookup_method parent;
54 };
55
56 struct lttng_userspace_probe_location_comm {
57 /* enum lttng_userspace_probe_location_type */
58 int8_t type;
59 /*
60 * Payload is composed of, in that order,
61 * - type-specific payload
62 * - struct lttng_userspace_probe_location_lookup_method_comm
63 */
64 char payload[];
65 };
66
67 struct lttng_userspace_probe_location_function_comm {
68 /* Both lengths include the trailing \0. */
69 uint32_t function_name_len;
70 uint32_t binary_path_len;
71 /*
72 * Payload is composed of, in that order,
73 * - function name (with trailing \0),
74 * - absolute binary path (with trailing \0)
75 */
76 char payload[];
77 } LTTNG_PACKED;
78
79 struct lttng_userspace_probe_location_tracepoint_comm {
80 /* The three lengths include the trailing \0. */
81 uint32_t probe_name_len;
82 uint32_t provider_name_len;
83 uint32_t binary_path_len;
84 /*
85 * Payload is composed of, in that order,
86 * - probe name (with trailing \0),
87 * - provider name (with trailing \0),
88 * - absolute binary path (with trailing \0)
89 */
90 char payload[];
91 } LTTNG_PACKED;
92
93 /* Common ancestor of all userspace probe locations. */
94 struct lttng_userspace_probe_location {
95 enum lttng_userspace_probe_location_type type;
96 struct lttng_userspace_probe_location_lookup_method *lookup_method;
97 userspace_probe_location_equal_cb equal;
98 userspace_probe_location_hash_cb hash;
99 userspace_probe_location_hash_cb mi;
100 };
101
102 struct lttng_userspace_probe_location_function {
103 struct lttng_userspace_probe_location parent;
104 char *function_name;
105 char *binary_path;
106 /*
107 * binary_fd is a file descriptor to the executable file. It's open
108 * early on to keep the backing inode valid over the course of the
109 * intrumentation and use. It prevents deletion and reuse races.
110 */
111 struct fd_handle *binary_fd_handle;
112 enum lttng_userspace_probe_location_function_instrumentation_type instrumentation_type;
113 };
114
115 struct lttng_userspace_probe_location_tracepoint {
116 struct lttng_userspace_probe_location parent;
117 char *probe_name;
118 char *provider_name;
119 char *binary_path;
120 /*
121 * binary_fd is a file descriptor to the executable file. It's open
122 * early on to keep the backing inode valid over the course of the
123 * intrumentation and use. It prevents deletion and reuse races.
124 */
125 struct fd_handle *binary_fd_handle;
126 };
127
128 int lttng_userspace_probe_location_serialize(const struct lttng_userspace_probe_location *location,
129 struct lttng_payload *payload);
130
131 int lttng_userspace_probe_location_create_from_payload(
132 struct lttng_payload_view *view, struct lttng_userspace_probe_location **probe_location);
133
134 /*
135 * Returns a version of the location that is serialized to a contiguous region
136 * of memory. Pass NULL to buffer to only get the storage requirement of the
137 * flattened userspace probe location.
138 */
139 int lttng_userspace_probe_location_flatten(const struct lttng_userspace_probe_location *location,
140 struct lttng_dynamic_buffer *buffer);
141
142 struct lttng_userspace_probe_location *
143 lttng_userspace_probe_location_copy(const struct lttng_userspace_probe_location *location);
144
145 bool lttng_userspace_probe_location_lookup_method_is_equal(
146 const struct lttng_userspace_probe_location_lookup_method *a,
147 const struct lttng_userspace_probe_location_lookup_method *b);
148
149 bool lttng_userspace_probe_location_is_equal(const struct lttng_userspace_probe_location *a,
150 const struct lttng_userspace_probe_location *b);
151
152 unsigned long
153 lttng_userspace_probe_location_hash(const struct lttng_userspace_probe_location *location);
154
155 enum lttng_error_code
156 lttng_userspace_probe_location_mi_serialize(const struct lttng_userspace_probe_location *location,
157 struct mi_writer *writer);
158
159 #endif /* LTTNG_USERSPACE_PROBE_INTERNAL_H */
This page took 0.031526 seconds and 4 git commands to generate.