forge_alloc_core/lib.rs
1//! # forge-alloc-core
2//!
3//! Core trait contracts and primitive layout type for the `forge-alloc`
4//! family of composable allocator crates.
5//!
6//! Defines the foundation that the higher layers depend on:
7//!
8//! - [`Allocator`] / [`Deallocator`] — the split allocation trait
9//! - [`NonZeroLayout`] — non-zero-size, power-of-two-align layout contract
10//! - [`StdCompat`] — bridge to [`allocator_api2::alloc::Allocator`]
11//! - [`OsBacked`] / [`FixedRange`] — structural traits for backings and ranges
12//! - [`FreelistProtection`] (+ [`NoProtection`], optional `SipHashMAC` / `PacMAC`)
13//! - [`AllocFaultPolicy`] — the OOM fault-injection seam for the
14//! `hardening` `Faulty` wrapper (+ built-in policies)
15//! - [`CachePadded`] — target-aware cache-line alignment wrapper for
16//! contended atomics
17//!
18//! Higher layers (the `backing`, `layout`, `hardening` modules) consume these
19//! traits to produce primitive types; the `forge-alloc` crate re-exports
20//! everything for convenience.
21//!
22//! # `testing` module
23//!
24//! Conformance helpers ([`testing::assert_fixed_range_invariants`],
25//! [`testing::assert_allocator_basic_round_trip`], etc.) live under
26//! [`testing`] for downstream crates that implement [`FixedRange`] or
27//! [`Allocator`] and want a ready-made trait-contract validator in
28//! their `#[test]` suite.
29
30#![cfg_attr(not(feature = "std"), no_std)]
31#![deny(unsafe_op_in_unsafe_fn)]
32#![warn(missing_docs)]
33
34extern crate alloc;
35
36pub mod cache_padded;
37pub mod testing;
38pub mod traits;
39
40pub use cache_padded::{CachePadded, CACHE_LINE};
41
42pub use traits::{
43 AllocError, AllocFaultPolicy, Allocator, AlwaysFail, Deallocator, FailAfter, FailEveryNth,
44 FailOnSize, FixedRange, FreelistCorruption, FreelistProtection, NeverFail, NoProtection,
45 NonZeroLayout, OsBacked, ProtectFlags, StdCompat,
46};
47
48#[cfg(feature = "siphasher")]
49pub use traits::SipHashMAC;
50
51#[cfg(all(target_arch = "aarch64", feature = "pac-stub"))]
52#[allow(deprecated)] // re-exporting the deprecated PacMAC stub is intentional
53pub use traits::PacMAC;