#![allow(unused_features)]
#![cfg_attr(feature = "unstable", feature(const_mut_refs))]
#![cfg_attr(test, feature(prelude_import, test, c_void_variant, core_intrinsics))]
#![no_std]
#![crate_name = "slabmalloc"]
#![crate_type = "lib"]
mod pages;
mod sc;
mod zone;
pub use pages::*;
pub use sc::*;
pub use zone::*;
#[cfg(test)]
#[macro_use]
extern crate std;
#[cfg(test)]
extern crate test;
#[cfg(test)]
mod tests;
use core::alloc::Layout;
use core::fmt;
use core::mem;
use core::ptr::{self, NonNull};
use log::trace;
const OBJECT_PAGE_METADATA_OVERHEAD: usize = 80;
const OBJECT_PAGE_SIZE: usize = 4096;
const LARGE_OBJECT_PAGE_SIZE: usize = 2 * 1024 * 1024;
type VAddr = usize;
#[derive(Debug)]
pub enum AllocationError {
OutOfMemory,
InvalidLayout,
}
pub unsafe trait Allocator<'a> {
fn allocate(&mut self, layout: Layout) -> Result<NonNull<u8>, AllocationError>;
fn deallocate(&mut self, ptr: NonNull<u8>, layout: Layout) -> Result<(), AllocationError>;
unsafe fn refill_large(
&mut self,
layout: Layout,
new_page: &'a mut LargeObjectPage<'a>,
) -> Result<(), AllocationError>;
unsafe fn refill(
&mut self,
layout: Layout,
new_page: &'a mut ObjectPage<'a>,
) -> Result<(), AllocationError>;
}