class VirtualAlloc

Defined at line 35 of file ../../zircon/kernel/lib/virtual_alloc/include/lib/virtual_alloc.h

VirtualAlloc is a page granule allocator that manages a given virtual region and provides

virtually contiguous allocations inside that region. This allocator explicitly has no dependency

on the heap and retrieves all its backing memory directly from the pmm. To achieve this it maps

pages directly into the hardware page tables via the arch aspace, and consequently assumes that

these operations will only depend on the pmm and not the heap for allocating any intermediate

page tables.

This class is thread-unsafe.

Public Methods

void VirtualAlloc (vm_page_state allocated_page_state)

Allocator needs to be told what state to set any allocated pages to. This allows for using the

allocator as a heap or generic allocator for an object.

Defined at line 36 of file ../../zircon/kernel/lib/virtual_alloc/virtual_alloc.cc

void VirtualAlloc (const VirtualAlloc & )

Defined at line 42 of file ../../zircon/kernel/lib/virtual_alloc/include/lib/virtual_alloc.h

void VirtualAlloc (VirtualAlloc && )

Defined at line 42 of file ../../zircon/kernel/lib/virtual_alloc/include/lib/virtual_alloc.h

VirtualAlloc & operator= (const VirtualAlloc & )

Defined at line 42 of file ../../zircon/kernel/lib/virtual_alloc/include/lib/virtual_alloc.h

VirtualAlloc & operator= (VirtualAlloc && )

Defined at line 42 of file ../../zircon/kernel/lib/virtual_alloc/include/lib/virtual_alloc.h

void ~VirtualAlloc ()

Defined at line 48 of file ../../zircon/kernel/lib/virtual_alloc/virtual_alloc.cc

zx_status_t Init (vaddr_t base, size_t size, size_t alloc_guard, size_t align_log2)

Initialize the allocator and make it ready for use. Takes a a virtual address range as a base

and size in bytes. These both must be page aligned and there must be no pages mapped into the

hardware page tables for this range.

|alloc_guard| is the minimum number of virtual pages to place between two allocations and

serve as guard pages. Any reads or writes that over or under run an allocation into the padding

will trigger an immediate hardware page fault.

Defined at line 50 of file ../../zircon/kernel/lib/virtual_alloc/virtual_alloc.cc

size_t DebugBitmapPages ()

Returns the number of pages allocated to provide the bitmap for tracking allocations. Exposed

as a debug named function as there is no promise that it has to be a bitmap for tracking and

this interface is likely to change and should only be used for debugging.

Defined at line 69 of file ../../zircon/kernel/lib/virtual_alloc/include/lib/virtual_alloc.h

zx::result<vaddr_t> AllocPages (size_t pages)

AllocPages can only be called after after a successful Init call, otherwise it will return an

error. Number of pages requested must be non zero.

Defined at line 180 of file ../../zircon/kernel/lib/virtual_alloc/virtual_alloc.cc

void FreePages (vaddr_t vaddr, size_t pages)

Returns a non-zero number of pages at the given virtual address. Partial frees are supported

such that if 2 pages were allocated at X it is allowed to FreePages(X, 1) and separately

FreePages(X + kPageSize, 1).

Defined at line 237 of file ../../zircon/kernel/lib/virtual_alloc/virtual_alloc.cc

bool CanAttemptContiguousMappings ()

Returns whether or not the allocator will attempt to optimize large allocations with

contiguous allocations and mappings that can get promoted to large pages. It does not guarantee

that it will succeed at doing this though.

Defined at line 410 of file ../../zircon/kernel/lib/virtual_alloc/virtual_alloc.cc

void DebugFreeAllAllocations ()

Frees any allocated pages as if FreePages had been called on every outstanding allocation. This

is exposed for testing for circumstances where externally tracking every allocations is

burdensome and not the goal of the test.

Defined at line 417 of file ../../zircon/kernel/lib/virtual_alloc/virtual_alloc.cc

void DebugAllocateVaddrRange (vaddr_t vaddr, size_t pages)

Force allocates the given range, overriding any padding or alignment requirements. This is used

for testing to more precisely control available allocation regions. Panics if range is invalid

or already allocated.

Defined at line 429 of file ../../zircon/kernel/lib/virtual_alloc/virtual_alloc.cc