2 * Copyright (C) 2017 Jérémie Galarneau <jeremie.galarneau@efficios.com>
3 * Copyright (C) 2018 Francis Deslauriers <francis.deslauriers@efficios.com>
5 * SPDX-License-Identifier: LGPL-2.1-only
9 #ifndef LTTNG_USERSPACE_PROBE_INTERNAL_H
10 #define LTTNG_USERSPACE_PROBE_INTERNAL_H
12 #include <common/fd-handle.hpp>
13 #include <common/macros.hpp>
15 #include <lttng/lttng-error.h>
16 #include <lttng/userspace-probe.h>
21 struct lttng_payload_view;
22 struct lttng_dynamic_buffer;
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);
33 * No elf-specific comm structure is defined since no elf-specific payload is
36 struct lttng_userspace_probe_location_lookup_method_comm {
37 /* enum lttng_userspace_probe_location_lookup_method_type */
39 /* type-specific payload */
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;
48 struct lttng_userspace_probe_location_lookup_method_elf {
49 struct lttng_userspace_probe_location_lookup_method parent;
52 struct lttng_userspace_probe_location_lookup_method_sdt {
53 struct lttng_userspace_probe_location_lookup_method parent;
56 struct lttng_userspace_probe_location_comm {
57 /* enum lttng_userspace_probe_location_type */
60 * Payload is composed of, in that order,
61 * - type-specific payload
62 * - struct lttng_userspace_probe_location_lookup_method_comm
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;
72 * Payload is composed of, in that order,
73 * - function name (with trailing \0),
74 * - absolute binary path (with trailing \0)
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;
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)
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;
102 struct lttng_userspace_probe_location_function {
103 struct lttng_userspace_probe_location parent;
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.
111 struct fd_handle *binary_fd_handle;
112 enum lttng_userspace_probe_location_function_instrumentation_type instrumentation_type;
115 struct lttng_userspace_probe_location_tracepoint {
116 struct lttng_userspace_probe_location parent;
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.
125 struct fd_handle *binary_fd_handle;
128 int lttng_userspace_probe_location_serialize(
129 const struct lttng_userspace_probe_location *location,
130 struct lttng_payload *payload);
132 int lttng_userspace_probe_location_create_from_payload(
133 struct lttng_payload_view *view,
134 struct lttng_userspace_probe_location **probe_location);
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.
141 int lttng_userspace_probe_location_flatten(
142 const struct lttng_userspace_probe_location *location,
143 struct lttng_dynamic_buffer *buffer);
145 struct lttng_userspace_probe_location *lttng_userspace_probe_location_copy(
146 const struct lttng_userspace_probe_location *location);
148 bool lttng_userspace_probe_location_lookup_method_is_equal(
149 const struct lttng_userspace_probe_location_lookup_method *a,
150 const struct lttng_userspace_probe_location_lookup_method *b);
152 bool lttng_userspace_probe_location_is_equal(
153 const struct lttng_userspace_probe_location *a,
154 const struct lttng_userspace_probe_location *b);
156 unsigned long lttng_userspace_probe_location_hash(
157 const struct lttng_userspace_probe_location *location);
159 enum lttng_error_code lttng_userspace_probe_location_mi_serialize(
160 const struct lttng_userspace_probe_location *location,
161 struct mi_writer *writer);
163 #endif /* LTTNG_USERSPACE_PROBE_INTERNAL_H */