pub unsafe trait Alloc<S>
where S: Size,
{ // Required methods fn alloc_range( &self, size: S, len: usize ) -> Result<PageRange<PAddr, S>, AllocErr>; fn dealloc_range(&self, range: PageRange<PAddr, S>) -> Result<(), AllocErr>; // Provided methods fn alloc(&self, size: S) -> Result<Page<PAddr, S>, AllocErr> { ... } fn dealloc(&self, page: Page<PAddr, S>) -> Result<(), AllocErr> { ... } }
Expand description

An allocator for physical pages of a given size.

Safety

This trait is unsafe to implement, as implementations are responsible for guaranteeing that allocated pages are unique, and may not be allocated by another page allocator.

Required Methods§

source

fn alloc_range( &self, size: S, len: usize ) -> Result<PageRange<PAddr, S>, AllocErr>

Allocate a range of len pages.

Returns
  • Ok(PageRange) if a range of pages was successfully allocated
  • Err if the requested range could not be satisfied by this allocator.
source

fn dealloc_range(&self, range: PageRange<PAddr, S>) -> Result<(), AllocErr>

Deallocate a range of pages.

Returns
  • Ok(()) if a range of pages was successfully deallocated
  • Err if the requested range could not be deallocated.

Provided Methods§

source

fn alloc(&self, size: S) -> Result<Page<PAddr, S>, AllocErr>

Allocate a single page.

Note that an implementation of this method is provided as long as an implementor of this trait provides alloc_range.

Returns
  • Ok(Page) if a page was successfully allocated.
  • Err if no more pages can be allocated by this allocator.
source

fn dealloc(&self, page: Page<PAddr, S>) -> Result<(), AllocErr>

Deallocate a single page.

Note that an implementation of this method is provided as long as an implementor of this trait provides dealloc_range.

Returns
  • Ok(()) if the page was successfully deallocated.
  • Err if the requested range could not be deallocated.

Implementations on Foreign Types§

source§

impl<S, const FREE_LISTS: usize> Alloc<S> for Alloc<FREE_LISTS>
where S: Size + Display,

source§

fn alloc_range( &self, size: S, len: usize ) -> Result<PageRange<PAddr, S>, AllocErr>

Allocate a range of at least len pages.

If len is not a power of two, the length is rounded up to the next power of two. The returned PageRange struct stores the actual length of the allocated page range.

Returns
  • Ok(PageRange) if a range of pages was successfully allocated
  • Err if the requested range could not be satisfied by this allocator.
source§

fn dealloc_range(&self, range: PageRange<PAddr, S>) -> Result<(), AllocErr>

Deallocate a range of pages.

Returns
  • Ok(()) if a range of pages was successfully deallocated
  • Err if the requested range could not be deallocated.

Implementors§

source§

impl<S> Alloc<S> for Allocator
where Alloc<32>: PageAlloc<S>, S: Size,

source§

impl<S> Alloc<S> for EmptyAlloc
where S: Size,