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

Virtual memory manager. More...

#include <stdint.h>
Include dependency graph for vmm.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  vmm_region
 Represents a virtual memory region. More...
struct  address_space
 Represents an address space. More...

Macros

#define VMM_TEST_BASE   0xFFFFC00000000000ULL

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).
void invlpg (void *virt)
 Invalidate a virtual address in the given address space.

Detailed Description

Virtual memory manager.

Author
Matheus Boscariol
Since
29/11/2026

Definition in file vmm.h.

Macro Definition Documentation

◆ VMM_TEST_BASE

#define VMM_TEST_BASE   0xFFFFC00000000000ULL

Definition at line 15 of file vmm.h.

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.

◆ invlpg()

void invlpg ( void * virt)
inline

Invalidate a virtual address in the given address space.

Parameters
virtThe virtual address to invalidate

Definition at line 86 of file vmm.h.

◆ 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: