buddy_core/buddy_err.rs
1/// Errors that can occur during buddy allocator operations.
2///
3/// These errors help ensure memory safety, catch double-free bugs,
4/// and detect structural corruptions inside the allocator state.
5
6#[derive(Debug, Clone, Copy, PartialEq, Eq)]
7pub enum BuddyError {
8 /// Discovered an attempt to free a block that is already marked as free or linked.
9 DoubleFree,
10
11 /// The metadata for the requested block index is either missing,
12 /// altered out of bounds, or structurally corrupted.
13 DataCorrupted,
14
15 /// No free blocks are available at the requested target order,
16 /// and higher orders cannot be split further.
17 NotFound,
18
19 /// The provided block address is not aligned properly with respect
20 /// to its allocation or buddy order.
21 AlignmentMismatch,
22}
23
24impl core::fmt::Display for BuddyError {
25 fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
26 match self {
27 Self::DoubleFree => write!(f, "Page double free detected"),
28 Self::DataCorrupted => write!(f, "Buddy metadata is corrupted or missing"),
29 Self::NotFound => write!(f, "No free block found at the requested order"),
30 Self::AlignmentMismatch => write!(f, "block not aligned"),
31 }
32 }
33}
34
35impl core::error::Error for BuddyError {}