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