Skip to main content

GlobalAllocator

Struct GlobalAllocator 

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

The global allocator used by ArceOS for axvisor.

This is an adapter around the buddy_slab_allocator::GlobalAllocator that provides compatibility with the original axalloc API and address translation support.

Implementations§

Source§

impl GlobalAllocator

Source

pub const fn new() -> Self

Creates an empty GlobalAllocator.

Source

pub const fn name(&self) -> &'static str

Returns the name of the allocator.

Source

pub fn init(&self, start_vaddr: usize, size: usize)

Initializes the allocator with the given region.

Source

pub fn set_addr_translator(&self, translator: &'static dyn AddrTranslator)

Set the address translator for the allocator.

Source

pub fn add_memory(&self, start_vaddr: usize, size: usize) -> AllocResult

Add the given region to the allocator.

Source

pub fn alloc(&self, layout: Layout) -> AllocResult<NonNull<u8>>

Allocate arbitrary number of bytes. Returns the left bound of the allocated region.

Source

pub fn dealloc(&self, pos: NonNull<u8>, layout: Layout)

Gives back the allocated region to the byte allocator.

Source

pub fn alloc_pages( &self, num_pages: usize, alignment: usize, kind: UsageKind, ) -> AllocResult<usize>

Allocates contiguous pages.

Source

pub fn alloc_dma32_pages( &self, num_pages: usize, alignment: usize, kind: UsageKind, ) -> AllocResult<usize>

Allocates contiguous low-memory pages (physical address < 4GiB).

Source

pub fn alloc_pages_at( &self, start: usize, num_pages: usize, alignment: usize, kind: UsageKind, ) -> AllocResult<usize>

Allocates contiguous pages starting from the given address.

Source

pub fn dealloc_pages(&self, pos: usize, num_pages: usize, kind: UsageKind)

Gives back the allocated pages starts from pos to the page allocator.

Source

pub fn used_bytes(&self) -> usize

Returns the number of allocated bytes in the byte allocator.

Source

pub fn available_bytes(&self) -> usize

Returns the number of available bytes in the byte allocator.

Source

pub fn used_pages(&self) -> usize

Returns the number of allocated pages in the page allocator.

Source

pub fn available_pages(&self) -> usize

Returns the number of available pages in the page allocator.

Source

pub fn usages(&self) -> Usages

Returns the usage statistics of the allocator.

Trait Implementations§

Source§

impl Default for GlobalAllocator

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl GlobalAlloc for GlobalAllocator

Source§

unsafe fn alloc(&self, layout: Layout) -> *mut u8

Allocates memory as described by the given layout. Read more
Source§

unsafe fn dealloc(&self, ptr: *mut u8, layout: Layout)

Deallocates the block of memory at the given ptr pointer with the given layout. Read more
1.28.0 · Source§

unsafe fn alloc_zeroed(&self, layout: Layout) -> *mut u8

Behaves like alloc, but also ensures that the contents are set to zero before being returned. Read more
1.28.0 · Source§

unsafe fn realloc( &self, ptr: *mut u8, layout: Layout, new_size: usize, ) -> *mut u8

Shrinks or grows a block of memory to the given new_size in bytes. The block is described by the given ptr pointer and layout. Read more

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.