![]() |
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 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 | |
| phyframe_t * | mm_get_free_page (void) |
| phyframe_t * | mm_get_free_page_raw (void) |
| phyframe_t * | mm_get_free_pages (size_t npages) |
| MMContext * | mm_create_context (void) |
| Create a user-mode platform-dependent page table. | |
| void | mm_destroy_context (MMContext *table) |
| Destroy a user-mode platform-dependent page table. | |
| void | mm_lock_context_pair (MMContext *ctx1, MMContext *ctx2=nullptr) |
| Lock and unlock a pair of MMContext objects. | |
| void | mm_unlock_context_pair (MMContext *ctx1, MMContext *ctx2=nullptr) |
| __nodiscard MMContext * | mm_switch_context (MMContext *new_ctx) |
| vmap_t * | vmap_create (MMContext *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 (MMContext *mmctx, ptr_t vaddr, size_t *out_offset=nullptr) |
| 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 83 of file mm.hpp.
Referenced by dmabuf_share(), dmabuf_unshare(), initrd_read(), platform_pml2e_get_pml1(), platform_pml3e_get_pml2(), platform_pml4e_get_pml3(), platform_startup_setup_kernel_mm(), pmm_init(), and x86_setup_direct_map().
| #define va_pfn | ( | va | ) |
Definition at line 84 of file mm.hpp.
Referenced by limine_entry(), pml2_traverse(), and pml2e_get_or_create_pml1().
| #define va_phyframe | ( | va | ) |
Definition at line 85 of file mm.hpp.
Referenced by __destroy_page_table(), pipe_close_one_end(), slab_impl_free_page(), and thread_destroy().
| #define phyframe_va | ( | frame | ) |
Definition at line 86 of file mm.hpp.
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 87 of file mm.hpp.
Referenced by do_handle_sdt_header(), do_iterate_sdts(), ioapic_init(), lapic_memory_setup(), platform_get_unix_timestamp(), platform_shutdown(), and platform_startup_late().
| #define mm_free_page | ( | frame | ) |
Definition at line 93 of file mm.hpp.
Referenced by __destroy_page_table().
| #define mm_free_pages | ( | frame, | |
| npages ) |
Definition at line 94 of file mm.hpp.
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 |
| phyframe_t * mm_get_free_page | ( | void | ) |
Definition at line 38 of file mm.cpp.
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 26 of file mm.cpp.
Referenced by mm_get_free_page().
| phyframe_t * mm_get_free_pages | ( | size_t | npages | ) |
Definition at line 47 of file mm.cpp.
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().
Create a user-mode platform-dependent page table.
Definition at line 59 of file mm.cpp.
Referenced by Process::Process().
Destroy a user-mode platform-dependent page table.
| table | The page table to destroy. |
Definition at line 75 of file mm.cpp.
Referenced by process_destroy().
Lock and unlock a pair of MMContext objects.
| ctx1 | The first context |
| ctx2 | The second context |
Definition at line 87 of file mm.cpp.
Referenced by mm_handle_fault(), mmap_file(), process_do_fork(), and thread_new().
Definition at line 105 of file mm.cpp.
Referenced by mm_handle_fault(), mmap_file(), process_do_fork(), and thread_new().
| __nodiscard MMContext * mm_switch_context | ( | MMContext * | new_ctx | ) |
Definition at line 124 of file mm.cpp.
Referenced by elf_do_fill_process(), and reschedule().
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 156 of file mm.cpp.
Referenced by mm_get_free_vaddr_locked().
Destroy a vmap object, and unmmap the region.
| vmap | The vmap object |
Definition at line 168 of file mm.cpp.
Referenced by dmabuf_free(), mmap_file(), munmap(), process_destroy(), process_do_execveat(), and thread_destroy().
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 189 of file mm.cpp.
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 209 of file mm.cpp.
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 231 of file mm.cpp.
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 254 of file mm.cpp.
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 270 of file mm.cpp.
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 363 of file mm.cpp.
Referenced by riscv64_trap_handler(), and x86_handle_exception().