The manual
ginnOS
The reference: libc, the libraries and the kernel
Loading...
Searching...
No Matches
vma.c File Reference
#include "arch/arch.h"
#include "vma.h"
#include "page.h"
#include "common/memory.h"

Functions

void vma_table_init (vma_table_t *table)
 empty a table.
void vma_table_copy (vma_table_t *dst, const vma_table_t *src)
 copy the areas of one table into another (fork).
kerr_t vma_insert (vma_table_t *table, uintptr_t start, uintptr_t end, uint32_t prot, vma_kind_t kind)
 add an area.
kerr_t vma_insert_locked (vma_table_t *table, uintptr_t start, uintptr_t end, uint32_t prot, vma_kind_t kind)
 vma_insert() for a caller that holds the table's lock.
vma_t * vma_find (vma_table_t *table, uintptr_t addr)
 find the area containing an address.
vma_t * vma_find_kind (vma_table_t *table, vma_kind_t kind)
 find the first area of a kind.
bool vma_range_free (const vma_table_t *table, uintptr_t start, uintptr_t end)
 check that no area overlaps a range.
uintptr_t vma_find_free (const vma_table_t *table, size_t length, uintptr_t low, uintptr_t high)
 find the lowest free gap of a given size inside [low, high).
kerr_t vma_remove (vma_table_t *table, uintptr_t start, uintptr_t end)
 unmap [start, end) from the table: areas inside it are removed, areas crossing its edges are trimmed, and an area containing it is split in two.
kerr_t vma_remove_locked (vma_table_t *table, uintptr_t start, uintptr_t end)
 vma_remove() for a caller that holds the table's lock.
kerr_t vma_protect (vma_table_t *table, uintptr_t start, uintptr_t end, uint32_t prot)
 change the protection of [start, end).
kerr_t vma_protect_locked (vma_table_t *table, uintptr_t start, uintptr_t end, uint32_t prot)
 vma_protect() for a caller that holds the table's lock.

Function Documentation

◆ vma_table_init()

void vma_table_init ( vma_table_t * table)

empty a table.

Parameters
tablethe table.

◆ vma_table_copy()

void vma_table_copy ( vma_table_t * dst,
const vma_table_t * src )

copy the areas of one table into another (fork).

the source's lock is held by the caller; the destination is not in use yet.

Parameters
dstthe new table.
srcthe table to copy.

◆ vma_insert()

kerr_t vma_insert ( vma_table_t * table,
uintptr_t start,
uintptr_t end,
uint32_t prot,
vma_kind_t kind )

add an area.

Parameters
tablethe table.
startfirst byte (page-aligned).
endfirst byte past the area (page-aligned, > start).
protPROT_* bits.
kindwhat backs it.
Returns
KERR_OK, KERR_INVAL for a bad range, KERR_EXIST if it overlaps an existing area, KERR_NOSPC if the table is full.

◆ vma_insert_locked()

kerr_t vma_insert_locked ( vma_table_t * table,
uintptr_t start,
uintptr_t end,
uint32_t prot,
vma_kind_t kind )

vma_insert() for a caller that holds the table's lock.

◆ vma_find()

vma_t * vma_find ( vma_table_t * table,
uintptr_t addr )

find the area containing an address.

Parameters
tablethe table.
addrthe address.
Returns
the area, or NULL if addr is not mapped by any.

◆ vma_find_kind()

vma_t * vma_find_kind ( vma_table_t * table,
vma_kind_t kind )

find the first area of a kind.

Parameters
tablethe table.
kindthe kind.
Returns
the area, or NULL if there is none.

◆ vma_range_free()

bool vma_range_free ( const vma_table_t * table,
uintptr_t start,
uintptr_t end )

check that no area overlaps a range.

Parameters
tablethe table.
startfirst byte of the range.
endfirst byte past the range.
Returns
true if [start, end) is entirely unmapped.

◆ vma_find_free()

uintptr_t vma_find_free ( const vma_table_t * table,
size_t length,
uintptr_t low,
uintptr_t high )

find the lowest free gap of a given size inside [low, high).

Parameters
tablethe table.
lengthbytes needed (page-aligned).
lowlowest acceptable start (page-aligned).
highfirst byte past the acceptable range.
Returns
the start of the gap, or 0 if none is large enough.

◆ vma_remove()

kerr_t vma_remove ( vma_table_t * table,
uintptr_t start,
uintptr_t end )

unmap [start, end) from the table: areas inside it are removed, areas crossing its edges are trimmed, and an area containing it is split in two.

Parameters
tablethe table.
startfirst byte (page-aligned).
endfirst byte past the range (page-aligned).
Returns
KERR_OK (also when nothing was mapped there), KERR_INVAL for a bad range, KERR_NOSPC if a split needs a slot and the table is full.

◆ vma_remove_locked()

kerr_t vma_remove_locked ( vma_table_t * table,
uintptr_t start,
uintptr_t end )

vma_remove() for a caller that holds the table's lock.

◆ vma_protect()

kerr_t vma_protect ( vma_table_t * table,
uintptr_t start,
uintptr_t end,
uint32_t prot )

change the protection of [start, end).

every byte of the range must be in some area; areas crossing its edges are split so only the range changes.

Parameters
tablethe table.
startfirst byte (page-aligned).
endfirst byte past the range (page-aligned).
protthe new PROT_* bits.
Returns
KERR_OK, KERR_INVAL for a bad range, KERR_NOENT if part of the range is unmapped, KERR_NOSPC if the splits need more slots than are free. on failure nothing changes.

◆ vma_protect_locked()

kerr_t vma_protect_locked ( vma_table_t * table,
uintptr_t start,
uintptr_t end,
uint32_t prot )

vma_protect() for a caller that holds the table's lock.