12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091 |
- #![allow(unused_features)]
- #![no_std]
- #![crate_name = "slabmalloc"]
- #![crate_type = "lib"]
- #![feature(maybe_uninit_as_bytes)]
- extern crate alloc;
- mod pages;
- mod sc;
- mod zone;
- pub use pages::*;
- pub use sc::*;
- pub use zone::*;
- use core::alloc::Layout;
- use core::fmt;
- use core::ptr::{self, NonNull};
- use log::trace;
- const OBJECT_PAGE_METADATA_OVERHEAD: usize = 80;
- const OBJECT_PAGE_SIZE: usize = 4096;
- 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>;
-
-
- unsafe fn deallocate(
- &mut self,
- ptr: NonNull<u8>,
- layout: Layout,
- slab_callback: &'static dyn CallBack,
- ) -> Result<(), AllocationError>;
-
-
-
-
- unsafe fn refill(
- &mut self,
- layout: Layout,
- new_page: &'a mut ObjectPage<'a>,
- ) -> Result<(), AllocationError>;
- }
- pub trait CallBack: Send + Sync {
-
-
- unsafe fn free_slab_page(&self, _: *mut u8, _: usize) {}
- }
|