MOS Source Code
|
Memory management functions and structures. More...
Topics | |
Paging | |
A platform-independent interface to map/unmap virtual memory to physical memory. | |
Physical Memory Manager | |
Allocate/free the physical memory, in the form of physical frames. | |
Classes | |
struct | pagefault_t |
struct | vmap_t |
Macros | |
#define | pfn_va(pfn) |
#define | va_pfn(va) |
#define | va_phyframe(va) |
#define | phyframe_va(frame) |
#define | pa_va(pa) |
#define | mm_free_page(frame) |
#define | mm_free_pages(frame, npages) |
Typedefs | |
typedef struct _vmap | vmap_t |
typedef vmfault_result_t(* | vmfault_handler_t) (vmap_t *vmap, ptr_t fault_addr, pagefault_t *info) |
Enumerations | |
enum | vmap_content_t { VMAP_UNKNOWN = 0 , VMAP_STACK , VMAP_FILE , VMAP_MMAP , VMAP_DMA } |
enum | vmap_type_t { VMAP_TYPE_PRIVATE = MMAP_PRIVATE , VMAP_TYPE_SHARED = MMAP_SHARED } |
enum | vmfault_result_t { VMFAULT_COMPLETE , VMFAULT_MAP_BACKING_PAGE_RO , VMFAULT_MAP_BACKING_PAGE , VMFAULT_COPY_BACKING_PAGE , VMFAULT_CANNOT_HANDLE = 0xff } |
Functions | |
__BEGIN_DECLS phyframe_t * | mm_get_free_page (void) |
phyframe_t * | mm_get_free_page_raw (void) |
phyframe_t * | mm_get_free_pages (size_t npages) |
mm_context_t * | mm_create_context (void) |
Create a user-mode platform-dependent page table. | |
void | mm_destroy_context (mm_context_t *table) |
Destroy a user-mode platform-dependent page table. | |
void | mm_lock_ctx_pair (mm_context_t *ctx1, mm_context_t *ctx2) |
Lock and unlock a pair of mm_context_t objects. | |
void | mm_unlock_ctx_pair (mm_context_t *ctx1, mm_context_t *ctx2) |
__nodiscard mm_context_t * | mm_switch_context (mm_context_t *new_ctx) |
vmap_t * | vmap_create (mm_context_t *mmctx, ptr_t vaddr, size_t npages) |
Create a vmap object and insert it into the address space. | |
void | vmap_destroy (vmap_t *vmap) |
Destroy a vmap object, and unmmap the region. | |
vmap_t * | vmap_obtain (mm_context_t *mmctx, ptr_t vaddr, size_t *out_offset) |
Get the vmap object for a virtual address. | |
vmap_t * | vmap_split (vmap_t *vmap, size_t split) |
Split a vmap object into two, at the specified offset. | |
vmap_t * | vmap_split_for_range (vmap_t *vmap, size_t rstart_pgoff, size_t rend_pgoff) |
Split a vmap to get a vmap object for a range of pages. | |
void | vmap_finalise_init (vmap_t *vmap, vmap_content_t content, vmap_type_t type) |
Finalize the initialization of a vmap object. | |
vmfault_result_t | mm_resolve_cow_fault (vmap_t *vmap, ptr_t fault_addr, pagefault_t *info) |
Helper function to resolve a copy-on-write fault. | |
void | mm_handle_fault (ptr_t fault_addr, pagefault_t *info) |
Handle a page fault. | |
Memory management functions and structures.
#define pfn_va | ( | pfn | ) |
Definition at line 76 of file mm.h.
Referenced by dmabuf_share(), dmabuf_unshare(), initrd_read(), platform_pml2e_get_pml1(), platform_pml2e_get_pml1(), platform_pml3e_get_pml2(), platform_pml3e_get_pml2(), platform_pml4e_get_pml3(), platform_pml4e_get_pml3(), platform_startup_setup_kernel_mm(), pmm_init(), and x86_setup_direct_map().
#define va_pfn | ( | va | ) |
Definition at line 77 of file mm.h.
Referenced by limine_entry(), pml2_traverse(), and pml2e_get_or_create_pml1().
#define va_phyframe | ( | va | ) |
Definition at line 78 of file mm.h.
Referenced by __destroy_page_table(), pipe_close_one_end(), slab_impl_free_page(), and thread_destroy().
#define phyframe_va | ( | frame | ) |
Definition at line 79 of file mm.h.
Referenced by __create_page_table(), cpio_fill_cache(), dmabuf_do_allocate(), mm_copy_page(), mm_get_free_page(), pipe_create(), process_do_fork(), register_sysfs_acpi_node(), register_sysfs_acpi_rsdp(), slab_impl_new_page(), sysfs_expand_buffer(), sysfs_fops_read(), sysfs_printf(), sysfs_put_data(), thread_new(), userfs_inode_cache_fill_cache(), userfs_inode_cache_flush_page(), vfs_read_pagecache(), vfs_write_pagecache(), and zero_page().
#define pa_va | ( | pa | ) |
Definition at line 80 of file mm.h.
Referenced by do_handle_sdt_header(), do_iterate_sdts(), ioapic_init(), lapic_memory_setup(), platform_shutdown(), platform_startup_late(), and riscv64_uart_setup().
#define mm_free_page | ( | frame | ) |
Definition at line 88 of file mm.h.
Referenced by __destroy_page_table().
#define mm_free_pages | ( | frame, | |
npages ) |
Definition at line 89 of file mm.h.
Referenced by pipe_close_one_end(), slab_impl_free_page(), sysfs_expand_buffer(), sysfs_fops_release(), and thread_destroy().
typedef vmfault_result_t(* vmfault_handler_t) (vmap_t *vmap, ptr_t fault_addr, pagefault_t *info) |
enum vmap_content_t |
enum vmap_type_t |
enum vmfault_result_t |
__BEGIN_DECLS phyframe_t * mm_get_free_page | ( | void | ) |
Definition at line 46 of file mm.c.
Referenced by __create_page_table(), cow_zod_fault_handler(), cpio_fill_cache(), mm_handle_fault(), mm_resolve_cow_fault(), tmpfs_fill_cache(), userfs_inode_cache_fill_cache(), and zero_page().
phyframe_t * mm_get_free_page_raw | ( | void | ) |
Definition at line 34 of file mm.c.
Referenced by mm_get_free_page().
phyframe_t * mm_get_free_pages | ( | size_t | npages | ) |
Definition at line 55 of file mm.c.
Referenced by pipe_create(), process_do_fork(), register_sysfs_acpi_node(), register_sysfs_acpi_rsdp(), slab_impl_new_page(), sysfs_expand_buffer(), and thread_new().
mm_context_t * mm_create_context | ( | void | ) |
Create a user-mode platform-dependent page table.
Definition at line 67 of file mm.c.
Referenced by process_allocate().
void mm_destroy_context | ( | mm_context_t * | table | ) |
Destroy a user-mode platform-dependent page table.
table | The page table to destroy. |
Definition at line 83 of file mm.c.
Referenced by process_destroy().
void mm_lock_ctx_pair | ( | mm_context_t * | ctx1, |
mm_context_t * | ctx2 ) |
Lock and unlock a pair of mm_context_t objects.
ctx1 | The first context |
ctx2 | The second context |
Definition at line 95 of file mm.c.
Referenced by mm_handle_fault(), mmap_file(), process_do_fork(), and thread_new().
void mm_unlock_ctx_pair | ( | mm_context_t * | ctx1, |
mm_context_t * | ctx2 ) |
Definition at line 111 of file mm.c.
Referenced by mm_handle_fault(), mmap_file(), process_do_fork(), and thread_new().
__nodiscard mm_context_t * mm_switch_context | ( | mm_context_t * | new_ctx | ) |
Definition at line 127 of file mm.c.
Referenced by elf_do_fill_process(), and reschedule().
vmap_t * vmap_create | ( | mm_context_t * | mmctx, |
ptr_t | vaddr, | ||
size_t | npages ) |
Create a vmap object and insert it into the address space.
mmctx | The address space |
vaddr | Starting virtual address of the region |
npages | Number of pages in the region |
Definition at line 159 of file mm.c.
Referenced by mm_get_free_vaddr_locked().
Destroy a vmap object, and unmmap the region.
vmap | The vmap object |
Definition at line 171 of file mm.c.
Referenced by dmabuf_free(), mmap_file(), munmap(), process_destroy(), process_do_execveat(), and thread_destroy().
vmap_t * vmap_obtain | ( | mm_context_t * | mmctx, |
ptr_t | vaddr, | ||
size_t * | out_offset ) |
Get the vmap object for a virtual address.
mmctx | The address space to search |
vaddr | The virtual address |
out_offset | An optional pointer to receive the offset of the address in the vmap |
Definition at line 192 of file mm.c.
Referenced by dmabuf_free(), mm_handle_fault(), munmap(), thread_destroy(), thread_new(), vm_protect(), and x86_dump_stack_at().
Split a vmap object into two, at the specified offset.
vmap | The vmap object |
split | The number of pages in the first vmap object |
Definition at line 212 of file mm.c.
Referenced by thread_new(), vm_protect(), and vmap_split_for_range().
Split a vmap to get a vmap object for a range of pages.
vmap | The vmap object to split |
rstart_pgoff | The starting page offset |
rend_pgoff | The ending page offset |
|----—|----—|----—| |begin |rstart |rend |end |----—|----—|----—|
Definition at line 234 of file mm.c.
Referenced by munmap().
void vmap_finalise_init | ( | vmap_t * | vmap, |
vmap_content_t | content, | ||
vmap_type_t | type ) |
Finalize the initialization of a vmap object.
vmap | The vmap object |
content | The content type of the region, |
type | The fork behavior of the region, |
Definition at line 257 of file mm.c.
Referenced by mm_map_user_pages(), mmap_anonymous(), mmap_file(), process_do_execveat(), process_do_fork(), and thread_new().
|
nodiscard |
Helper function to resolve a copy-on-write fault.
vmap | The vmap object |
fault_addr | The fault address |
info | The page fault info |
Definition at line 273 of file mm.c.
Referenced by cow_zod_fault_handler(), and vfs_fault_handler().
void mm_handle_fault | ( | ptr_t | fault_addr, |
pagefault_t * | info ) |
Handle a page fault.
fault_addr | The fault address |
info | The page fault info |
Definition at line 365 of file mm.c.
Referenced by riscv64_trap_handler(), and x86_handle_exception().