libdd_profiling/internal/
mapping.rs

1// Copyright 2023-Present Datadog, Inc. https://www.datadoghq.com/
2// SPDX-License-Identifier: Apache-2.0
3
4use super::*;
5
6/// Represents a [pprof::Mapping] with some space-saving changes:
7///  - The id is not stored on the struct. It's stored in the container that holds the struct.
8///  - ids for linked objects use 32-bit numbers instead of 64 bit ones.
9#[derive(Eq, PartialEq, Hash)]
10pub struct Mapping {
11    /// Address at which the binary (or DLL) is loaded into memory.
12    pub memory_start: u64,
13    /// The limit of the address range occupied by this mapping.
14    pub memory_limit: u64,
15    /// Offset in the binary that corresponds to the first mapped address.
16    pub file_offset: u64,
17
18    /// The object this entry is loaded from.  This can be a filename on
19    /// disk for the main binary and shared libraries, or virtual
20    /// abstractions like "[vdso]".
21    pub filename: StringId,
22
23    /// A string that uniquely identifies a particular program version
24    /// with high probability. E.g., for binaries generated by GNU tools,
25    /// it could be the contents of the .note.gnu.build-id field.
26    pub build_id: StringId,
27}
28
29impl Item for Mapping {
30    type Id = MappingId;
31}
32
33#[derive(Copy, Clone, Debug, Eq, PartialEq, Hash, PartialOrd, Ord)]
34#[repr(C)]
35pub struct MappingId(NonZeroU32);
36
37impl Id for MappingId {
38    type RawId = u64;
39
40    fn from_offset(offset: usize) -> Self {
41        #[allow(clippy::expect_used)]
42        Self(small_non_zero_pprof_id(offset).expect("MappingId to fit into a u32"))
43    }
44
45    fn to_raw_id(&self) -> Self::RawId {
46        self.0.get().into()
47    }
48}