Commit | Line | Data |
---|---|---|
1ce46cfe | 1 | /* |
ab5be9fa MJ |
2 | * Copyright (C) 2017 Jérémie Galarneau <jeremie.galarneau@efficios.com> |
3 | * Copyright (C) 2018 Francis Deslauriers <francis.deslauriers@efficios.com> | |
1ce46cfe | 4 | * |
ab5be9fa | 5 | * SPDX-License-Identifier: LGPL-2.1-only |
1ce46cfe | 6 | * |
1ce46cfe JG |
7 | */ |
8 | ||
9 | #ifndef LTTNG_USERSPACE_PROBE_INTERNAL_H | |
10 | #define LTTNG_USERSPACE_PROBE_INTERNAL_H | |
11 | ||
c9e313bc | 12 | #include <common/fd-handle.hpp> |
e665dfbc JG |
13 | #include <common/macros.hpp> |
14 | ||
15 | #include <lttng/lttng-error.h> | |
16 | #include <lttng/userspace-probe.h> | |
17 | ||
e368fb43 JG |
18 | #include <stdbool.h> |
19 | ||
20 | struct lttng_payload; | |
21 | struct lttng_payload_view; | |
22 | struct lttng_dynamic_buffer; | |
6a751b95 | 23 | struct mi_writer; |
1ce46cfe | 24 | |
e665dfbc JG |
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); | |
dfcfa983 | 31 | |
1ce46cfe JG |
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 | ||
f4d0bb2e FD |
52 | struct lttng_userspace_probe_location_lookup_method_sdt { |
53 | struct lttng_userspace_probe_location_lookup_method parent; | |
54 | }; | |
55 | ||
1ce46cfe JG |
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 | ||
f4d0bb2e FD |
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 | ||
1ce46cfe JG |
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; | |
dfcfa983 | 97 | userspace_probe_location_equal_cb equal; |
959e3c66 | 98 | userspace_probe_location_hash_cb hash; |
6a751b95 | 99 | userspace_probe_location_hash_cb mi; |
1ce46cfe JG |
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. | |
1ce46cfe | 110 | */ |
2cde0510 | 111 | struct fd_handle *binary_fd_handle; |
9d3981b5 | 112 | enum lttng_userspace_probe_location_function_instrumentation_type instrumentation_type; |
1ce46cfe JG |
113 | }; |
114 | ||
f4d0bb2e FD |
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. | |
f4d0bb2e | 124 | */ |
2cde0510 | 125 | struct fd_handle *binary_fd_handle; |
f4d0bb2e FD |
126 | }; |
127 | ||
28f23191 JG |
128 | int lttng_userspace_probe_location_serialize(const struct lttng_userspace_probe_location *location, |
129 | struct lttng_payload *payload); | |
1ce46cfe | 130 | |
e368fb43 | 131 | int lttng_userspace_probe_location_create_from_payload( |
28f23191 | 132 | struct lttng_payload_view *view, struct lttng_userspace_probe_location **probe_location); |
1ce46cfe | 133 | |
1ce46cfe JG |
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 | */ | |
28f23191 JG |
139 | int lttng_userspace_probe_location_flatten(const struct lttng_userspace_probe_location *location, |
140 | struct lttng_dynamic_buffer *buffer); | |
1ce46cfe | 141 | |
28f23191 JG |
142 | struct lttng_userspace_probe_location * |
143 | lttng_userspace_probe_location_copy(const struct lttng_userspace_probe_location *location); | |
394357fe | 144 | |
dfcfa983 | 145 | bool lttng_userspace_probe_location_lookup_method_is_equal( |
28f23191 JG |
146 | const struct lttng_userspace_probe_location_lookup_method *a, |
147 | const struct lttng_userspace_probe_location_lookup_method *b); | |
dfcfa983 | 148 | |
28f23191 JG |
149 | bool lttng_userspace_probe_location_is_equal(const struct lttng_userspace_probe_location *a, |
150 | const struct lttng_userspace_probe_location *b); | |
dfcfa983 | 151 | |
28f23191 JG |
152 | unsigned long |
153 | lttng_userspace_probe_location_hash(const struct lttng_userspace_probe_location *location); | |
959e3c66 | 154 | |
28f23191 JG |
155 | enum lttng_error_code |
156 | lttng_userspace_probe_location_mi_serialize(const struct lttng_userspace_probe_location *location, | |
157 | struct mi_writer *writer); | |
6a751b95 | 158 | |
1ce46cfe | 159 | #endif /* LTTNG_USERSPACE_PROBE_INTERNAL_H */ |