Skip to main content

ax_percpu/
error.rs

1use cpu_local::{CpuAreaRef, CpuIndex, CpuLocalError};
2
3/// Failure to initialize, locate, or access a runtime per-CPU area.
4#[derive(Clone, Copy, Debug, Eq, PartialEq, thiserror::Error)]
5pub enum PerCpuError {
6    /// One area cannot hold the fixed CPU-local prefix.
7    #[error("per-CPU template size {actual:#x} is smaller than {minimum:#x}")]
8    AreaTooSmall {
9        /// Actual linked template size.
10        actual: usize,
11        /// Minimum supported prefix size.
12        minimum: usize,
13    },
14    /// Adjacent runtime areas overlap.
15    #[error("per-CPU stride {stride:#x} is smaller than area size {area_size:#x}")]
16    StrideTooSmall {
17        /// Supplied stride.
18        stride: usize,
19        /// Linked template size.
20        area_size: usize,
21    },
22    /// Runtime base is not aligned for all generated symbols.
23    #[error("per-CPU runtime base {base:#x} is not aligned to {alignment:#x}")]
24    MisalignedRuntimeBase {
25        /// Supplied runtime base.
26        base: usize,
27        /// Required alignment.
28        alignment: usize,
29    },
30    /// Area stride does not preserve required alignment.
31    #[error("per-CPU stride {stride:#x} is not aligned to {alignment:#x}")]
32    MisalignedStride {
33        /// Supplied stride.
34        stride: usize,
35        /// Required alignment.
36        alignment: usize,
37    },
38    /// The linked template base does not preserve every symbol's alignment.
39    #[error("per-CPU template base {base:#x} is not aligned to {alignment:#x}")]
40    MisalignedTemplateBase {
41        /// Loaded template base.
42        base: usize,
43        /// Required alignment.
44        alignment: usize,
45    },
46    /// Linker-provided alignment boundaries are inconsistent.
47    #[error("per-CPU alignment metadata range {start:#x}..{end:#x} is malformed")]
48    MalformedAlignmentMetadata {
49        /// First descriptor address.
50        start: usize,
51        /// One-past-the-end descriptor address.
52        end: usize,
53    },
54    /// A generated alignment is not a nonzero power of two.
55    #[error("per-CPU symbol alignment descriptor {0:#x} is invalid")]
56    InvalidSymbolAlignment(usize),
57    /// The linker layout and generated descriptor table disagree.
58    #[error(
59        "per-CPU alignment descriptors require {descriptors:#x}, but linker reports {linker:#x}"
60    )]
61    AlignmentMetadataMismatch {
62        /// Maximum generated alignment.
63        descriptors: usize,
64        /// Alignment encoded by the linker.
65        linker: usize,
66    },
67    /// Address calculation overflowed.
68    #[error("per-CPU layout address calculation overflowed")]
69    AddressOverflow,
70    /// Initializer table boundaries are inconsistent.
71    #[error("per-CPU initializer table range {start:#x}..{end:#x} is malformed")]
72    MalformedInitTable {
73        /// First registration address.
74        start: usize,
75        /// One-past-the-end registration address.
76        end: usize,
77    },
78    /// One typed initializer does not fit the template layout.
79    #[error(
80        "per-CPU initializer {index} has invalid offset {offset:#x}, size {size:#x}, or alignment \
81         {alignment:#x}"
82    )]
83    MalformedInitRecord {
84        /// Registration index in the final image.
85        index: usize,
86        /// Destination offset.
87        offset: usize,
88        /// Storage size.
89        size: usize,
90        /// Storage alignment.
91        alignment: usize,
92    },
93    /// Two typed initializer destinations overlap.
94    #[error("per-CPU initializer destinations overlap at {first_offset:#x} and {second_offset:#x}")]
95    OverlappingInitRecords {
96        /// First overlapping offset.
97        first_offset: usize,
98        /// Second overlapping offset.
99        second_offset: usize,
100    },
101    /// Another initialization attempt is active.
102    #[error("per-CPU layout initialization is already in progress")]
103    LayoutInitializationInProgress,
104    /// The one-shot layout has already been installed.
105    #[error("per-CPU layout has already been initialized")]
106    LayoutAlreadyInitialized,
107    /// The target does not provide an ELF initializer table.
108    #[error("per-CPU typed initializer table is unavailable on this target")]
109    InitializerTableUnavailable,
110    /// The CPU-local prefix is not first in the template.
111    #[error(
112        "per-CPU template base {template_base:#x} differs from prefix address {prefix_address:#x}"
113    )]
114    PrefixPlacement {
115        /// Loaded template start.
116        template_base: usize,
117        /// Fixed prefix symbol address.
118        prefix_address: usize,
119    },
120    /// No runtime layout has been installed.
121    #[error("per-CPU runtime layout is not installed")]
122    LayoutNotInstalled,
123    /// Requested logical CPU is outside the installed region.
124    #[error("CPU {cpu_index:?} is outside layout area count {area_count}")]
125    CpuOutOfRange {
126        /// Requested CPU.
127        cpu_index: CpuIndex,
128        /// Installed area count.
129        area_count: u32,
130    },
131    /// A supplied current CPU area differs from the installed area.
132    #[error("current CPU area {actual:?} differs from expected {expected:?}")]
133    CurrentAreaMismatch {
134        /// Area selected by the installed layout.
135        expected: CpuAreaRef,
136        /// Area carried by the pin.
137        actual: CpuAreaRef,
138    },
139    /// CPU-local prefix construction or validation failed.
140    #[error(transparent)]
141    CpuLocal(#[from] CpuLocalError),
142}