diff options
| author | Richard Qin <richard.qin.x@gmail.com> | 2026-05-13 15:56:08 +0800 |
|---|---|---|
| committer | Richard Qin <richard.qin.x@gmail.com> | 2026-05-13 15:56:08 +0800 |
| commit | d6b81de2a1377858929c79f6be84108b023b5b00 (patch) | |
| tree | fe6050fdaa5a615e56210c2e750190a24f050494 /na/include | |
| parent | 70fa5d207fecf4db0eef58f2b6120bdd0b0f3e96 (diff) | |
| download | lume-d6b81de2a1377858929c79f6be84108b023b5b00.tar.gz lume-d6b81de2a1377858929c79f6be84108b023b5b00.tar.xz | |
feat: update Virtual Memory Manager to use page-based allocation and introduce VmFaultCause enum
Diffstat (limited to 'na/include')
| -rw-r--r-- | na/include/lume/vmm.h | 30 |
1 files changed, 22 insertions, 8 deletions
diff --git a/na/include/lume/vmm.h b/na/include/lume/vmm.h index ec26d6a..85988e4 100644 --- a/na/include/lume/vmm.h +++ b/na/include/lume/vmm.h @@ -26,6 +26,12 @@ inline constexpr uint64 VM_WRITE = (1ULL << 1); inline constexpr uint64 VM_EXEC = (1ULL << 2); inline constexpr uint64 VM_USER = (1ULL << 3); +enum class VmFaultCause : uint8 { + Read = 0, + Write = 1, + Exec = 2, +}; + /* Forward declarations */ struct VmSpace; struct VmAreaStruct; @@ -48,13 +54,16 @@ struct VmAreaStruct { * * Lock contract: * Holds: lock (internal spinlock) - * May acquire: PMM global lock (via pmm_alloc_frame inside page fault) + * May acquire: PMM global lock (via pmm_alloc_page inside page fault) * Callers must NOT hold: PMM lock (lock ordering: VmSpace -> PMM) */ struct VmSpace { uint64 root_pa; // SV39 root page table physical address struct rb_root vma_tree; // Red-black tree of VmAreaStructs Spinlock lock; // Protects vma_tree mutations + + uint64 brk_start; // Start of heap (page-aligned) + uint64 brk_end; // Current heap end (page-aligned) // Create a brand new VmSpace (allocates root pagetable) static VmSpace* create(); @@ -72,18 +81,23 @@ void vmm_init_ap(); /* Map MMIO device region to the active kernel page table */ void vmm_map_kernel_mmio(uint64 pa, uint64 size); -/* Query frame_map allocation (set by vmm_init, read by pmm_init). - * Returns the PA, byte size, and frame count of the vmemmap region. */ -uint64 vmm_get_frame_map_pa(); -uint64 vmm_get_frame_map_size(); -uint64 vmm_get_num_frames(); +/* Query page_map allocation (set by vmm_init, read by pmm_init). + * Returns the PA, byte size, and page count of the vmemmap region. */ +uint64 vmm_get_page_map_pa(); +uint64 vmm_get_page_map_size(); +uint64 vmm_get_num_pages(); /* User space memory management (VMA & Demand Paging) */ int vmm_map_user(VmSpace* space, uint64 va, uint64 len, uint64 perm); int vmm_unmap_user(VmSpace* space, uint64 va, uint64 len); +int vmm_protect_user(VmSpace* space, uint64 va, uint64 len, uint64 perm); + +/* VMA helpers for mmap/mprotect implementations */ +uint64 mm_find_free_va(VmSpace* space, uint64 length, uint64 align); +bool vma_range_covered(VmSpace* space, uint64 start, uint64 end); -/* Handle user page fault (lookup VMA -> allocate frame -> map) */ -int vmm_handle_page_fault(VmSpace* space, uint64 fault_addr, uint64 cause); +/* Handle user page fault (lookup VMA -> allocate page -> map) */ +int vmm_handle_page_fault(VmSpace* space, uint64 fault_addr, VmFaultCause cause); /* Clone an address space for fork() */ VmSpace* vmm_clone(VmSpace* parent_space); |
