ef6a5726e1edf64710dea6826ea8472e5aa9555a
[lttng-tools.git] / include / lttng / userspace-probe-internal.h
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 <lttng/userspace-probe.h>
13 #include <common/macros.h>
14 #include <common/dynamic-buffer.h>
15 #include <common/buffer-view.h>
16
17 typedef bool (*userspace_probe_location_equal_cb)(
18 const struct lttng_userspace_probe_location *a,
19 const struct lttng_userspace_probe_location *b);
20
21 /*
22 * No elf-specific comm structure is defined since no elf-specific payload is
23 * currently needed.
24 */
25 struct lttng_userspace_probe_location_lookup_method_comm {
26 /* enum lttng_userspace_probe_location_lookup_method_type */
27 int8_t type;
28 /* type-specific payload */
29 char payload[];
30 };
31
32 /* Common ancestor of all userspace probe location lookup methods. */
33 struct lttng_userspace_probe_location_lookup_method {
34 enum lttng_userspace_probe_location_lookup_method_type type;
35 };
36
37 struct lttng_userspace_probe_location_lookup_method_elf {
38 struct lttng_userspace_probe_location_lookup_method parent;
39 };
40
41 struct lttng_userspace_probe_location_lookup_method_sdt {
42 struct lttng_userspace_probe_location_lookup_method parent;
43 };
44
45 struct lttng_userspace_probe_location_comm {
46 /* enum lttng_userspace_probe_location_type */
47 int8_t type;
48 /*
49 * Payload is composed of, in that order,
50 * - type-specific payload
51 * - struct lttng_userspace_probe_location_lookup_method_comm
52 */
53 char payload[];
54 };
55
56 struct lttng_userspace_probe_location_function_comm {
57 /* Both lengths include the trailing \0. */
58 uint32_t function_name_len;
59 uint32_t binary_path_len;
60 /*
61 * Payload is composed of, in that order,
62 * - function name (with trailing \0),
63 * - absolute binary path (with trailing \0)
64 */
65 char payload[];
66 } LTTNG_PACKED;
67
68 struct lttng_userspace_probe_location_tracepoint_comm {
69 /* The three lengths include the trailing \0. */
70 uint32_t probe_name_len;
71 uint32_t provider_name_len;
72 uint32_t binary_path_len;
73 /*
74 * Payload is composed of, in that order,
75 * - probe name (with trailing \0),
76 * - provider name (with trailing \0),
77 * - absolute binary path (with trailing \0)
78 */
79 char payload[];
80 } LTTNG_PACKED;
81
82 /* Common ancestor of all userspace probe locations. */
83 struct lttng_userspace_probe_location {
84 enum lttng_userspace_probe_location_type type;
85 struct lttng_userspace_probe_location_lookup_method *lookup_method;
86 userspace_probe_location_equal_cb equal;
87 };
88
89 struct lttng_userspace_probe_location_function {
90 struct lttng_userspace_probe_location parent;
91 char *function_name;
92 char *binary_path;
93 /*
94 * binary_fd is a file descriptor to the executable file. It's open
95 * early on to keep the backing inode valid over the course of the
96 * intrumentation and use. It prevents deletion and reuse races.
97 * Set to -1 if not open.
98 */
99 int binary_fd;
100 enum lttng_userspace_probe_location_function_instrumentation_type instrumentation_type;
101 };
102
103 struct lttng_userspace_probe_location_tracepoint {
104 struct lttng_userspace_probe_location parent;
105 char *probe_name;
106 char *provider_name;
107 char *binary_path;
108 /*
109 * binary_fd is a file descriptor to the executable file. It's open
110 * early on to keep the backing inode valid over the course of the
111 * intrumentation and use. It prevents deletion and reuse races.
112 * Set to -1 if not open.
113 */
114 int binary_fd;
115 };
116
117 LTTNG_HIDDEN
118 int lttng_userspace_probe_location_serialize(
119 const struct lttng_userspace_probe_location *location,
120 struct lttng_dynamic_buffer *buffer,
121 int *binary_fd);
122
123 LTTNG_HIDDEN
124 int lttng_userspace_probe_location_create_from_buffer(
125 const struct lttng_buffer_view *buffer,
126 struct lttng_userspace_probe_location **probe_location);
127
128 LTTNG_HIDDEN
129 int lttng_userspace_probe_location_function_set_binary_fd(
130 struct lttng_userspace_probe_location *location, int binary_fd);
131
132 LTTNG_HIDDEN
133 int lttng_userspace_probe_location_tracepoint_set_binary_fd(
134 struct lttng_userspace_probe_location *location, int binary_fd);
135
136 /*
137 * Returns a version of the location that is serialized to a contiguous region
138 * of memory. Pass NULL to buffer to only get the storage requirement of the
139 * flattened userspace probe location.
140 */
141 LTTNG_HIDDEN
142 int lttng_userspace_probe_location_flatten(
143 const struct lttng_userspace_probe_location *location,
144 struct lttng_dynamic_buffer *buffer);
145
146 LTTNG_HIDDEN
147 struct lttng_userspace_probe_location *lttng_userspace_probe_location_copy(
148 const struct lttng_userspace_probe_location *location);
149
150 LTTNG_HIDDEN
151 bool lttng_userspace_probe_location_is_equal(
152 const struct lttng_userspace_probe_location *a,
153 const struct lttng_userspace_probe_location *b);
154
155 LTTNG_HIDDEN
156 int lttng_userspace_probe_location_set_binary_fd(
157 struct lttng_userspace_probe_location *location, int fd);
158
159 #endif /* LTTNG_USERSPACE_PROBE_INTERNAL_H */
This page took 0.047556 seconds and 5 git commands to generate.