LumaOS  v0.1.116
An experimental x86-64 OS
Loading...
Searching...
No Matches
vmm.c File Reference

Virtual memory manager. More...

#include <stdbool.h>
#include <mm/vmm.h>
#include <mm/pmm.h>
#include <arch/x86_64/paging.h>
#include <kernel/log.h>
#include <kernel/vars.h>
Include dependency graph for vmm.c:

Go to the source code of this file.

Functions

uint64_t get_kernel_pml4_phys (void)
 Returns the physical address of the top-level table.
void vmm_init (void)
 Initialize the virtual memory manager and the kernel address space.
void vmm_add_region (uint64_t start, uint64_t end, uint64_t flags)
 Add a region to the kernel address space.
uint64_t vmm_map (uint64_t pml4_phys, uint64_t virtual_address, uint64_t physical_address, uint64_t flags)
 Maps a virtual address to a physical address in the given address space.
uint64_t vmm_unmap (uint64_t pml4_phys, uint64_t virtual_address)
 Unmaps a virtual address in the given address space.
bool vmm_page_fault_handler (uint64_t fault_address, uint64_t error_code)
 Handles a page fault in the given address space (demand paging).

Variables

struct address_space kernel_address_space

Detailed Description

Virtual memory manager.

Author
Matheus Boscariol
Since
29/11/2026

Definition in file vmm.c.

Function Documentation

◆ get_kernel_pml4_phys()

uint64_t get_kernel_pml4_phys ( void )

Returns the physical address of the top-level table.

Returns
The physical address of the top-level table

Definition at line 19 of file vmm.c.

◆ vmm_add_region()

void vmm_add_region ( uint64_t start,
uint64_t end,
uint64_t flags )

Add a region to the kernel address space.

Parameters
startThe starting virtual address of the region (4 KiB aligned)
endThe ending virtual address of the region (4 KiB aligned)
flagsThe PTE flags to use when a page of the region is mapped

Definition at line 33 of file vmm.c.

◆ vmm_init()

void vmm_init ( void )

Initialize the virtual memory manager and the kernel address space.

Definition at line 24 of file vmm.c.

◆ vmm_map()

uint64_t vmm_map ( uint64_t pml4_phys,
uint64_t virtual_address,
uint64_t physical_address,
uint64_t flags )

Maps a virtual address to a physical address in the given address space.

Parameters
pml4_physThe physical address of the top-level table
virtual_addressThe virtual address to map
physical_addressThe physical address to map to
flagsThe PTE flags to use when a page of the region is mapped
Returns
The virtual address of the mapped page, or UINT64_MAX if mapping failed

Definition at line 47 of file vmm.c.

Here is the call graph for this function:

◆ vmm_page_fault_handler()

bool vmm_page_fault_handler ( uint64_t fault_address,
uint64_t error_code )

Handles a page fault in the given address space (demand paging).

Parameters
fault_addressThe virtual address that caused the page fault
error_codeThe error code associated with the page fault
Returns
True if the page fault was handled successfully, false otherwise

Definition at line 163 of file vmm.c.

Here is the call graph for this function:

◆ vmm_unmap()

uint64_t vmm_unmap ( uint64_t pml4_phys,
uint64_t virtual_address )

Unmaps a virtual address in the given address space.

Parameters
pml4_physThe physical address of the top-level table
virtual_addressThe virtual address to unmap
Returns
The physical address of the unmapped frame, or UINT64_MAX if unmapping failed

Definition at line 116 of file vmm.c.

Here is the call graph for this function:

Variable Documentation

◆ kernel_address_space

struct address_space kernel_address_space

Definition at line 17 of file vmm.c.