MOS Source Code
Loading...
Searching...
No Matches

A platform-independent interface to map/unmap virtual memory to physical memory. More...

+ Collaboration diagram for Paging:

Enumerations

enum  valloc_flags { VALLOC_DEFAULT = 0 , VALLOC_EXACT = MMAP_EXACT }
 

Functions

vmap_tmm_get_free_vaddr_locked (mm_context_t *mmctx, size_t n_pages, ptr_t base_vaddr, valloc_flags flags)
 Gets npages unmapped free pages from a page table.
 
void mm_map_kernel_pages (mm_context_t *mmctx, ptr_t vaddr, pfn_t pfn, size_t npages, vm_flags flags)
 Map a block of virtual memory to a block of physical memory.
 
vmap_tmm_map_user_pages (mm_context_t *mmctx, ptr_t vaddr, pfn_t pfn, size_t npages, vm_flags flags, valloc_flags vaflags, vmap_type_t type, vmap_content_t content)
 
void mm_replace_page_locked (mm_context_t *mmctx, ptr_t vaddr, pfn_t pfn, vm_flags flags)
 Replace the mappings of a page with a new physical frame.
 
vmap_tmm_clone_vmap_locked (vmap_t *src_vmap, mm_context_t *dst_ctx)
 Remap a block of virtual memory from one page table to another, i.e. copy the mappings.
 
bool mm_get_is_mapped_locked (mm_context_t *mmctx, ptr_t vaddr)
 Get if a virtual address is mapped in a page table.
 
void mm_flag_pages_locked (mm_context_t *mmctx, ptr_t vaddr, size_t npages, vm_flags flags)
 Update the flags of a block of virtual memory.
 
ptr_t mm_get_phys_addr (mm_context_t *ctx, ptr_t vaddr)
 

Detailed Description

A platform-independent interface to map/unmap virtual memory to physical memory.

Enumeration Type Documentation

◆ valloc_flags

Enumerator
VALLOC_DEFAULT 

Default allocation flags.

VALLOC_EXACT 

Allocate pages at the exact address.

Definition at line 19 of file paging.h.

Function Documentation

◆ mm_get_free_vaddr_locked()

vmap_t * mm_get_free_vaddr_locked ( mm_context_t * mmctx,
size_t n_pages,
ptr_t base_vaddr,
valloc_flags flags )

Gets npages unmapped free pages from a page table.

Parameters
mmctxThe memory management context to allocate from.
n_pagesThe number of pages to allocate.
base_vaddrThe base virtual address to allocate at.
flagsFlags to set on the pages, see valloc_flags.
Returns
ptr_t The virtual address of the block of virtual memory.
Note
This function neither allocates nor maps the pages, it only determines the block of virtual memory that can be used to allocate and map the pages.
The returned vmap_t only contains the virtual address and the number of pages, it does not contain any physical addresses, nor the flags of the pages.
Warning
Should call with mmctx->mm_lock held.

Definition at line 18 of file paging.c.

Referenced by cow_allocate_zeroed_pages(), mm_clone_vmap_locked(), mm_map_user_pages(), and mmap_file().

+ Here is the call graph for this function:

◆ mm_map_kernel_pages()

void mm_map_kernel_pages ( mm_context_t * mmctx,
ptr_t vaddr,
pfn_t pfn,
size_t npages,
vm_flags flags )

Map a block of virtual memory to a block of physical memory.

Parameters
mmctxThe memory management context to map to.
vaddrThe virtual address to map to.
pfnThe physical frame to map from.
npagesThe number of pages to map.
flagsFlags to set on the pages, see vm_flags.

This function maps the pages in the block, their reference count will NOT be incremented.

Note
This function is rarely used directly, you don't always know the physical address of the pages you want to map.

Definition at line 79 of file paging.c.

Referenced by x86_paging_setup().

+ Here is the call graph for this function:

◆ mm_map_user_pages()

vmap_t * mm_map_user_pages ( mm_context_t * mmctx,
ptr_t vaddr,
pfn_t pfn,
size_t npages,
vm_flags flags,
valloc_flags vaflags,
vmap_type_t type,
vmap_content_t content )

Definition at line 89 of file paging.c.

Referenced by dmabuf_allocate(), and mos_start_kernel().

+ Here is the call graph for this function:

◆ mm_replace_page_locked()

void mm_replace_page_locked ( mm_context_t * mmctx,
ptr_t vaddr,
pfn_t pfn,
vm_flags flags )

Replace the mappings of a page with a new physical frame.

Parameters
mmctxThe memory management context to replace in.
vaddrThe virtual address to replace.
pfnThe physical frame to replace to.
flagsThe new flags to set on the pages.
Note
The reference count of the physical frame will be incremented, and the reference count of the old physical frame will be decremented.

Definition at line 109 of file paging.c.

Referenced by mm_handle_fault(), and mm_resolve_cow_fault().

+ Here is the call graph for this function:

◆ mm_clone_vmap_locked()

vmap_t * mm_clone_vmap_locked ( vmap_t * src_vmap,
mm_context_t * dst_ctx )

Remap a block of virtual memory from one page table to another, i.e. copy the mappings.

Parameters
src_vmapThe source vmap
dst_ctxThe destination paging context

This function firstly unmaps the pages in the destination page table, then copies the pages mappings, including the flags and physical addresses, the physical page reference count is updated accordingly.

Note
If clear_dest is set to true, then the destination page table is cleared before copying, otherwise the function assumes that there are no existing mappings in the destination page table.

Definition at line 129 of file paging.c.

Referenced by cow_clone_vmap_locked(), and process_do_fork().

+ Here is the call graph for this function:

◆ mm_get_is_mapped_locked()

bool mm_get_is_mapped_locked ( mm_context_t * mmctx,
ptr_t vaddr )

Get if a virtual address is mapped in a page table.

Parameters
mmctxThe memory management context to check in.
vaddrThe virtual address to get the physical address of.
Returns
bool True if the virtual address is mapped, false otherwise.

Definition at line 156 of file paging.c.

+ Here is the call graph for this function:

◆ mm_flag_pages_locked()

void mm_flag_pages_locked ( mm_context_t * mmctx,
ptr_t vaddr,
size_t npages,
vm_flags flags )

Update the flags of a block of virtual memory.

Parameters
mmctxThe memory management context to update the flags in.
vaddrThe virtual address to update the flags of.
npagesThe number of pages to update the flags of.
flagsThe flags to set on the pages, see vm_flags.

Definition at line 168 of file paging.c.

Referenced by cow_clone_vmap_locked().

+ Here is the call graph for this function:

◆ mm_get_phys_addr()

ptr_t mm_get_phys_addr ( mm_context_t * ctx,
ptr_t vaddr )

Definition at line 176 of file paging.c.

Referenced by futex_get_key(), and x86_dump_stack_at().

+ Here is the call graph for this function: