|
ginnOS
The reference: libc, the libraries and the kernel
|
Go to the source code of this file.
Data Structures | |
| struct | vma_t |
| one area of user memory. More... | |
| struct | vma_table_t |
| a process's areas, sorted by start. More... | |
Macros | |
| #define | VMA_MAX 256 |
| virtual memory areas: what a process has mapped in its user half. | |
Enumerations | |
| enum | vma_kind_t { VMA_ELF , VMA_HEAP , VMA_STACK , VMA_ANON , VMA_DEVICE , VMA_SHARED } |
| what backs an area. More... | |
Functions | |
| void | vma_table_init (vma_table_t *table) |
| empty a table. | |
| kerr_t | vma_insert (vma_table_t *table, uintptr_t start, uintptr_t end, uint32_t prot, vma_kind_t kind) |
| add an area. | |
| 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_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. | |
| 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. | |
| 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_protect (vma_table_t *table, uintptr_t start, uintptr_t end, uint32_t prot) |
| change the protection of [start, end). | |
| #define VMA_MAX 256 |
virtual memory areas: what a process has mapped in its user half.
each area is a page-aligned [start, end) range with protection bits and a kind (ELF segment, heap, stack, anonymous or device mmap). a process keeps its areas in a vma_table_t, sorted by start and never overlapping. the table is what the page-fault handler consults and what mmap/munmap work on.
locking: the threads of a process share the table. the memory syscalls take the user space's mutex (user_space.h), so one changes it at a time. the table's spinlock (the page lock, as mm->page_table_lock in Linux) guards the table and the page tables of the space: each change holds it, so a page fault in another thread (mm_fault_in, which holds it too) never sees half of one. the functions that change the table take it; vma_find and the other readers do not, so their caller holds it, or the user space's mutex, or the space is not in use yet.
| enum vma_kind_t |
| void vma_table_init | ( | vma_table_t * | table | ) |
empty a table.
| table | the table. |
| kerr_t vma_insert | ( | vma_table_t * | table, |
| uintptr_t | start, | ||
| uintptr_t | end, | ||
| uint32_t | prot, | ||
| vma_kind_t | kind ) |
add an area.
| table | the table. |
| start | first byte (page-aligned). |
| end | first byte past the area (page-aligned, > start). |
| prot | PROT_* bits. |
| kind | what backs it. |
| vma_t * vma_find | ( | vma_table_t * | table, |
| uintptr_t | addr ) |
find the area containing an address.
| table | the table. |
| addr | the address. |
| vma_t * vma_find_kind | ( | vma_table_t * | table, |
| vma_kind_t | kind ) |
find the first area of a kind.
| table | the table. |
| kind | the kind. |
| bool vma_range_free | ( | const vma_table_t * | table, |
| uintptr_t | start, | ||
| uintptr_t | end ) |
check that no area overlaps a range.
| table | the table. |
| start | first byte of the range. |
| end | first byte past the 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).
| table | the table. |
| length | bytes needed (page-aligned). |
| low | lowest acceptable start (page-aligned). |
| high | first byte past the acceptable range. |
| 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.
| table | the table. |
| start | first byte (page-aligned). |
| end | first byte past the range (page-aligned). |
| 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_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.
| 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.
| 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.
| dst | the new table. |
| src | the table to copy. |
| 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.
| table | the table. |
| start | first byte (page-aligned). |
| end | first byte past the range (page-aligned). |
| prot | the new PROT_* bits. |