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 <lttng/userspace-probe.h>
13 #include <common/macros.h>
14 #include <common/fd-handle.h>
18 struct lttng_payload_view
;
19 struct lttng_dynamic_buffer
;
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
,
32 * No elf-specific comm structure is defined since no elf-specific payload is
35 struct lttng_userspace_probe_location_lookup_method_comm
{
36 /* enum lttng_userspace_probe_location_lookup_method_type */
38 /* type-specific payload */
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
;
47 struct lttng_userspace_probe_location_lookup_method_elf
{
48 struct lttng_userspace_probe_location_lookup_method parent
;
51 struct lttng_userspace_probe_location_lookup_method_sdt
{
52 struct lttng_userspace_probe_location_lookup_method parent
;
55 struct lttng_userspace_probe_location_comm
{
56 /* enum lttng_userspace_probe_location_type */
59 * Payload is composed of, in that order,
60 * - type-specific payload
61 * - struct lttng_userspace_probe_location_lookup_method_comm
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
;
71 * Payload is composed of, in that order,
72 * - function name (with trailing \0),
73 * - absolute binary path (with trailing \0)
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
;
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)
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
;
101 struct lttng_userspace_probe_location_function
{
102 struct lttng_userspace_probe_location parent
;
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.
110 struct fd_handle
*binary_fd_handle
;
111 enum lttng_userspace_probe_location_function_instrumentation_type instrumentation_type
;
114 struct lttng_userspace_probe_location_tracepoint
{
115 struct lttng_userspace_probe_location parent
;
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.
124 struct fd_handle
*binary_fd_handle
;
127 int lttng_userspace_probe_location_serialize(
128 const struct lttng_userspace_probe_location
*location
,
129 struct lttng_payload
*payload
);
131 int lttng_userspace_probe_location_create_from_payload(
132 struct lttng_payload_view
*view
,
133 struct lttng_userspace_probe_location
**probe_location
);
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.
140 int lttng_userspace_probe_location_flatten(
141 const struct lttng_userspace_probe_location
*location
,
142 struct lttng_dynamic_buffer
*buffer
);
144 struct lttng_userspace_probe_location
*lttng_userspace_probe_location_copy(
145 const struct lttng_userspace_probe_location
*location
);
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
);
151 bool lttng_userspace_probe_location_is_equal(
152 const struct lttng_userspace_probe_location
*a
,
153 const struct lttng_userspace_probe_location
*b
);
155 unsigned long lttng_userspace_probe_location_hash(
156 const struct lttng_userspace_probe_location
*location
);
158 enum lttng_error_code
lttng_userspace_probe_location_mi_serialize(
159 const struct lttng_userspace_probe_location
*location
,
160 struct mi_writer
*writer
);
162 #endif /* LTTNG_USERSPACE_PROBE_INTERNAL_H */