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
impl GlobalAllocator
Sourcepub const fn new() -> Self
pub const fn new() -> Self
Creates an empty GlobalAllocator.
Sourcepub fn init(&self, start_vaddr: usize, size: usize)
pub fn init(&self, start_vaddr: usize, size: usize)
Initializes the allocator with the given region.
Sourcepub fn set_addr_translator(&self, translator: &'static dyn AddrTranslator)
pub fn set_addr_translator(&self, translator: &'static dyn AddrTranslator)
Set the address translator for the allocator.
Sourcepub fn add_memory(&self, start_vaddr: usize, size: usize) -> AllocResult
pub fn add_memory(&self, start_vaddr: usize, size: usize) -> AllocResult
Add the given region to the allocator.
Sourcepub fn alloc(&self, layout: Layout) -> AllocResult<NonNull<u8>>
pub fn alloc(&self, layout: Layout) -> AllocResult<NonNull<u8>>
Allocate arbitrary number of bytes. Returns the left bound of the allocated region.
Sourcepub fn dealloc(&self, pos: NonNull<u8>, layout: Layout)
pub fn dealloc(&self, pos: NonNull<u8>, layout: Layout)
Gives back the allocated region to the byte allocator.
Sourcepub fn alloc_pages(
&self,
num_pages: usize,
alignment: usize,
kind: UsageKind,
) -> AllocResult<usize>
pub fn alloc_pages( &self, num_pages: usize, alignment: usize, kind: UsageKind, ) -> AllocResult<usize>
Allocates contiguous pages.
Sourcepub fn alloc_dma32_pages(
&self,
num_pages: usize,
alignment: usize,
kind: UsageKind,
) -> AllocResult<usize>
pub fn alloc_dma32_pages( &self, num_pages: usize, alignment: usize, kind: UsageKind, ) -> AllocResult<usize>
Allocates contiguous low-memory pages (physical address < 4GiB).
Sourcepub fn alloc_pages_at(
&self,
start: usize,
num_pages: usize,
alignment: usize,
kind: UsageKind,
) -> AllocResult<usize>
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.
Sourcepub fn dealloc_pages(&self, pos: usize, num_pages: usize, kind: UsageKind)
pub fn dealloc_pages(&self, pos: usize, num_pages: usize, kind: UsageKind)
Gives back the allocated pages starts from pos to the page allocator.
Sourcepub fn used_bytes(&self) -> usize
pub fn used_bytes(&self) -> usize
Returns the number of allocated bytes in the byte allocator.
Sourcepub fn available_bytes(&self) -> usize
pub fn available_bytes(&self) -> usize
Returns the number of available bytes in the byte allocator.
Sourcepub fn used_pages(&self) -> usize
pub fn used_pages(&self) -> usize
Returns the number of allocated pages in the page allocator.
Sourcepub fn available_pages(&self) -> usize
pub fn available_pages(&self) -> usize
Returns the number of available pages in the page allocator.
Trait Implementations§
Source§impl Default for GlobalAllocator
impl Default for GlobalAllocator
Source§impl GlobalAlloc for GlobalAllocator
impl GlobalAlloc for GlobalAllocator
Source§unsafe fn alloc(&self, layout: Layout) -> *mut u8
unsafe fn alloc(&self, layout: Layout) -> *mut u8
layout. Read more