AquilaOS documentation
How it works, and its code
Loading...
Searching...
No Matches
vm_space.c File Reference

Address spaces: a process's mappings (map entries), kept in address order, and its page tables (pmap). More...

#include <core/system.h>
#include <core/arch.h>
#include <mm/pmap.h>
#include <mm/vm.h>
#include <ds/queue.h>

Go to the source code of this file.

Functions

int vm_space_insert (struct vm_space *vm_space, struct vm_entry *vm_entry)
 Adds a map entry to an address space, in address order.
struct vm_entry * vm_space_find (struct vm_space *vm_space, vaddr_t vaddr)
 Finds the map entry that an address is in.
void vm_space_destroy (struct vm_space *vm_space)
 Removes all the mappings of an address space: its entries are released and freed, and its page tables emptied.
int vm_space_fork (struct vm_space *src, struct vm_space *dst)
 Copies an address space's mappings into another, for fork().

Detailed Description

Address spaces: a process's mappings (map entries), kept in address order, and its page tables (pmap).

Definition in file vm_space.c.

Function Documentation

◆ vm_space_destroy()

void vm_space_destroy ( struct vm_space * vm_space)

Removes all the mappings of an address space: its entries are released and freed, and its page tables emptied.

Parameters
vm_spacethe address space (NULL does nothing)

Definition at line 124 of file vm_space.c.

References kfree(), NULL, vm_space::pmap, pmap_remove_all(), vm_space::vm_entries, vm_entry_destroy(), and vm_space_destroy().

Referenced by binfmt_fmt_load(), proc_fork(), proc_kill(), and vm_space_destroy().

◆ vm_space_find()

struct vm_entry * vm_space_find ( struct vm_space * vm_space,
vaddr_t vaddr )

Finds the map entry that an address is in.

Parameters
vm_spacethe address space
vaddrthe address
Returns
the entry, or NULL if no mapping covers the address

Definition at line 99 of file vm_space.c.

References vm_entry::base, NULL, PAGE_ALIGN, queue_for, vm_entry::size, vm_space::vm_entries, and vm_space_find().

Referenced by mm_page_fault(), and vm_space_find().

◆ vm_space_fork()

int vm_space_fork ( struct vm_space * src,
struct vm_space * dst )

Copies an address space's mappings into another, for fork().

The two share the pages, copy on write: writable private mappings become read-only in src, and their anons are marked to be copied, so that the first write to a page gives the writer its own copy (mm/fault.c).

Parameters
srcthe parent's address space
dstthe child's address space, empty
Returns
0, -EINVAL if either is NULL, or -ENOMEM if there was no memory for an entry; what was copied stays in dst, for the caller to destroy

Definition at line 152 of file vm_space.c.

References vm_entry::base, vm_anon::flags, vm_entry::flags, kfree(), kmalloc(), memcpy(), vm_space::pmap, pmap_protect(), vm_entry::qnode, queue_for, vm_entry::size, vm_entry::vm_anon, vm_anon_incref(), VM_COPY, vm_space::vm_entries, VM_KW, vm_entry::vm_object, vm_object_incref(), VM_SHARED, vm_space_fork(), and VM_UW.

Referenced by proc_fork(), and vm_space_fork().

◆ vm_space_insert()

int vm_space_insert ( struct vm_space * vm_space,
struct vm_entry * vm_entry )

Adds a map entry to an address space, in address order.

If the entry's base is 0, the entry is placed at the highest free gap between mappings that it fits in. The entry always goes before an existing one (the stack's, at the top of user space): an entry past the last one can't be added.

Parameters
vm_spacethe address space
vm_entrythe entry, with its base (or 0) and size set
Returns
0, -EINVAL if either is NULL, or -ENOMEM if there is no room for it, or no memory for its list node

Definition at line 27 of file vm_space.c.

References vm_entry::base, queue::count, queue::head, kmalloc(), M_ZERO, qnode::next, NULL, qnode::prev, vm_entry::qnode, queue_for, vm_entry::size, qnode::value, vm_space::vm_entries, and vm_space_insert().

Referenced by arch_sigcode_map(), sys_mmap(), and vm_space_insert().