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§
Provided Methods§
sourcefn alloc(&self, size: S) -> Result<Page<PAddr, S>, AllocErr>
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.
sourcefn dealloc(&self, page: Page<PAddr, S>) -> Result<(), AllocErr>
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.