| 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 | * This library is free software; you can redistribute it and/or modify it |
| 6 | * under the terms of the GNU Lesser General Public License, version 2.1 only, |
| 7 | * as published by the Free Software Foundation. |
| 8 | * |
| 9 | * This library is distributed in the hope that it will be useful, but WITHOUT |
| 10 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
| 11 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License |
| 12 | * for more details. |
| 13 | * |
| 14 | * You should have received a copy of the GNU Lesser General Public License |
| 15 | * along with this library; if not, write to the Free Software Foundation, |
| 16 | * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
| 17 | */ |
| 18 | |
| 19 | #ifndef LTTNG_USERSPACE_PROBE_INTERNAL_H |
| 20 | #define LTTNG_USERSPACE_PROBE_INTERNAL_H |
| 21 | |
| 22 | #include <lttng/userspace-probe.h> |
| 23 | #include <common/macros.h> |
| 24 | #include <common/dynamic-buffer.h> |
| 25 | #include <common/buffer-view.h> |
| 26 | |
| 27 | /* |
| 28 | * No elf-specific comm structure is defined since no elf-specific payload is |
| 29 | * currently needed. |
| 30 | */ |
| 31 | struct lttng_userspace_probe_location_lookup_method_comm { |
| 32 | /* enum lttng_userspace_probe_location_lookup_method_type */ |
| 33 | int8_t type; |
| 34 | /* type-specific payload */ |
| 35 | char payload[]; |
| 36 | }; |
| 37 | |
| 38 | /* Common ancestor of all userspace probe location lookup methods. */ |
| 39 | struct lttng_userspace_probe_location_lookup_method { |
| 40 | enum lttng_userspace_probe_location_lookup_method_type type; |
| 41 | }; |
| 42 | |
| 43 | struct lttng_userspace_probe_location_lookup_method_elf { |
| 44 | struct lttng_userspace_probe_location_lookup_method parent; |
| 45 | }; |
| 46 | |
| 47 | struct lttng_userspace_probe_location_comm { |
| 48 | /* enum lttng_userspace_probe_location_type */ |
| 49 | int8_t type; |
| 50 | /* |
| 51 | * Payload is composed of, in that order, |
| 52 | * - type-specific payload |
| 53 | * - struct lttng_userspace_probe_location_lookup_method_comm |
| 54 | */ |
| 55 | char payload[]; |
| 56 | }; |
| 57 | |
| 58 | struct lttng_userspace_probe_location_function_comm { |
| 59 | /* Both lengths include the trailing \0. */ |
| 60 | uint32_t function_name_len; |
| 61 | uint32_t binary_path_len; |
| 62 | /* |
| 63 | * Payload is composed of, in that order, |
| 64 | * - function name (with trailing \0), |
| 65 | * - absolute binary path (with trailing \0) |
| 66 | */ |
| 67 | char payload[]; |
| 68 | } LTTNG_PACKED; |
| 69 | |
| 70 | /* Common ancestor of all userspace probe locations. */ |
| 71 | struct lttng_userspace_probe_location { |
| 72 | enum lttng_userspace_probe_location_type type; |
| 73 | struct lttng_userspace_probe_location_lookup_method *lookup_method; |
| 74 | }; |
| 75 | |
| 76 | struct lttng_userspace_probe_location_function { |
| 77 | struct lttng_userspace_probe_location parent; |
| 78 | char *function_name; |
| 79 | char *binary_path; |
| 80 | /* |
| 81 | * binary_fd is a file descriptor to the executable file. It's open |
| 82 | * early on to keep the backing inode valid over the course of the |
| 83 | * intrumentation and use. It prevents deletion and reuse races. |
| 84 | * Set to -1 if not open. |
| 85 | */ |
| 86 | int binary_fd; |
| 87 | }; |
| 88 | |
| 89 | LTTNG_HIDDEN |
| 90 | int lttng_userspace_probe_location_serialize( |
| 91 | const struct lttng_userspace_probe_location *location, |
| 92 | struct lttng_dynamic_buffer *buffer, |
| 93 | int *binary_fd); |
| 94 | |
| 95 | LTTNG_HIDDEN |
| 96 | int lttng_userspace_probe_location_create_from_buffer( |
| 97 | const struct lttng_buffer_view *buffer, |
| 98 | struct lttng_userspace_probe_location **probe_location); |
| 99 | |
| 100 | LTTNG_HIDDEN |
| 101 | int lttng_userspace_probe_location_function_set_binary_fd( |
| 102 | struct lttng_userspace_probe_location *location, int binary_fd); |
| 103 | |
| 104 | /* |
| 105 | * Returns a version of the location that is serialized to a contiguous region |
| 106 | * of memory. Pass NULL to buffer to only get the storage requirement of the |
| 107 | * flattened userspace probe location. |
| 108 | */ |
| 109 | LTTNG_HIDDEN |
| 110 | int lttng_userspace_probe_location_flatten( |
| 111 | const struct lttng_userspace_probe_location *location, |
| 112 | struct lttng_dynamic_buffer *buffer); |
| 113 | |
| 114 | LTTNG_HIDDEN |
| 115 | struct lttng_userspace_probe_location *lttng_userspace_probe_location_copy( |
| 116 | const struct lttng_userspace_probe_location *location); |
| 117 | |
| 118 | #endif /* LTTNG_USERSPACE_PROBE_INTERNAL_H */ |