ps_alloc/
error.rs

1#![allow(clippy::module_name_repetitions)]
2
3use std::alloc::LayoutError;
4
5use thiserror::Error;
6
7#[derive(Debug, Error, PartialEq, Eq, Clone)]
8pub enum AllocationError {
9    #[error("An arithmetic error occured.")]
10    ArithmeticError,
11    #[error("The allocated memory was not properly aligned.")]
12    ImproperAlignment,
13    #[error(transparent)]
14    LayoutError(#[from] LayoutError),
15    #[error("Process ran out of memory.")]
16    OutOfMemory,
17}
18
19#[derive(Debug, Error, PartialEq, Eq, Clone)]
20pub enum DeallocationError {
21    #[error("This memory was already freed.")]
22    DoubleFree,
23    #[error("The pointer provided was not properly aligned.")]
24    ImproperAlignment,
25    #[error("Tried to free memory not allocated by this crate.")]
26    InvalidAllocation,
27    #[error(transparent)]
28    LayoutError(#[from] LayoutError),
29    #[error("Tried to free a null pointer.")]
30    NullPtr,
31}
32
33#[derive(Debug, Error, PartialEq, Eq, Clone)]
34pub enum ReallocationError {
35    #[error(transparent)]
36    AllocationError(#[from] AllocationError),
37    #[error(transparent)]
38    DeallocationError(#[from] DeallocationError),
39    #[error("Deallocation failed, cleanup failed: {0}, {1}")]
40    FreeFailedTwice(DeallocationError, DeallocationError),
41    #[error("Refusing to realloc an improperly aligned pointer.")]
42    ImproperAlignment,
43    #[error("Refusing to realloc a pointer not allocated by ps-alloc.")]
44    InvalidPointer,
45    #[error("Refusing to realloc a freed pointer.")]
46    UseAfterFree,
47}