Trait hal_core::mem::page::Alloc

source ·
pub unsafe trait Alloc<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.

Implementors§

source§

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