hyperlight_common/virtq/pool.rs
1// SPDX-License-Identifier: Apache-2.0
2// Copyright 2026 The Hyperlight Authors.
3//! Fixed-slot allocation for virtqueue payloads.
4
5use thiserror::Error;
6
7mod slot;
8
9pub use slot::{SlotLayout, SlotPool};
10
11/// Buffer allocation failure.
12#[derive(Debug, Error, Copy, Clone)]
13pub enum AllocError {
14 /// An address does not identify a live allocation.
15 #[error("Invalid free addr {0} and size {1}")]
16 InvalidFree(u64, usize),
17 /// An argument is zero or otherwise invalid.
18 #[error("Invalid argument")]
19 InvalidArg,
20 /// A region cannot hold any allocation.
21 #[error("Empty region")]
22 EmptyRegion,
23 /// No currently free allocation can satisfy the request.
24 #[error("No space available")]
25 NoSpace,
26 /// The request exceeds the pool's allocation capacity.
27 #[error("Requested size exceeds pool capacity")]
28 OutOfMemory,
29 /// Allocation bookkeeping could not be reserved.
30 #[error("Failed to allocate buffer bookkeeping")]
31 Bookkeeping,
32 /// Address or size arithmetic overflowed.
33 #[error("Overflow")]
34 Overflow,
35}
36
37/// One pool allocation.
38#[derive(Debug, Clone, Copy)]
39pub struct Allocation {
40 /// Starting address of the allocation.
41 pub addr: u64,
42 /// Nonzero descriptor-safe capacity in bytes.
43 pub len: u32,
44}
45
46#[cfg(test)]
47mod tests;
48
49#[cfg(test)]
50mod fuzz;