kernel::grant

Struct GrantRegionAllocator

Source
pub struct GrantRegionAllocator { /* private fields */ }
Expand description

Tool for allocating additional memory regions in a process’s grant region.

This is optionally provided along with a grant so that if a capsule needs per-process dynamic allocation it can allocate additional memory.

Implementations§

Source§

impl GrantRegionAllocator

Source

pub fn alloc_with<T, F>(&self, init: F) -> Result<CustomGrant<T>, Error>
where F: FnOnce() -> T,

Allocates a new CustomGrant initialized using the given closure.

The closure will be called exactly once, and the result will be used to initialize the owned value.

This interface was chosen instead of a simple alloc(val) as it’s much more likely to optimize out all stack intermediates. This helps to prevent stack overflows when allocating large values.

§Panic Safety

If init panics, the freshly allocated memory may leak.

Source

pub fn alloc_n_with<T, F, const NUM_ITEMS: usize>( &self, init: F, ) -> Result<CustomGrant<[T; NUM_ITEMS]>, Error>
where F: FnMut(usize) -> T,

Allocates a slice of n instances of a given type. Each instance is initialized using the provided function.

The provided function will be called exactly n times, and will be passed the index it’s initializing, from 0 through NUM_ITEMS - 1.

§Panic Safety

If val_func panics, the freshly allocated memory and any values already written will be leaked.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.