PatchworkOS
Loading...
Searching...
No Matches
paging.h File Reference
#include <kernel/cpu/regs.h>
#include <kernel/mem/paging_types.h>
#include <assert.h>
#include <stdbool.h>
#include <stdlib.h>
#include <string.h>
#include <sys/proc.h>

Go to the source code of this file.

Data Structures

struct  page_table_traverse_t
 Helper structure for fast traversal of the page table. More...
 
struct  page_table_page_buffer_t
 Buffer of pages used to batch page frees. More...
 

Macros

#define PAGE_TABLE_TRAVERSE_CREATE
 Create a page_table_traverse_t initializer.
 

Functions

static void tlb_invalidate (void *virtAddr, uint64_t pageCount)
 Invalidates a region of pages in the TLB.
 
static uintptr_t pml_accessible_addr (pml_entry_t entry)
 Retrieves the address from a page table entry and converts it to an accessible address.
 
static bool pml_is_empty (pml_t *pml)
 Checks if a page table level is empty (all entries are 0).
 
static uint64_t pml_new (page_table_t *table, pml_t **outPml)
 Allocates and initializes a new page table level.
 
static void pml_free (page_table_t *table, pml_t *pml, pml_level_t level)
 Recursively frees a page table level, all its children and any owned pages.
 
static uint64_t page_table_init (page_table_t *table, pml_alloc_pages_t allocPages, pml_free_pages_t freePages)
 Initializes a page table.
 
static void page_table_deinit (page_table_t *table)
 Deinitializes a page table, freeing all allocated pages.
 
static void page_table_load (page_table_t *table)
 Loads the page table into the CR3 register if it is not already loaded.
 
static uint64_t page_table_get_pml (page_table_t *table, pml_t *currentPml, pml_index_t index, pml_flags_t flags, pml_t **outPml)
 Retrieves or allocates the next level page table.
 
static uint64_t page_table_traverse (page_table_t *table, page_table_traverse_t *traverse, uintptr_t virtAddr, pml_flags_t flags)
 Allows for fast traversal of the page table by caching previously accessed layers.
 
static uint64_t page_table_get_phys_addr (page_table_t *table, const void *virtAddr, void **outPhysAddr)
 Retrieves the physical address mapped to a given virtual address.
 
static bool page_table_is_mapped (page_table_t *table, const void *virtAddr, uint64_t pageAmount)
 Checks if a range of virtual addresses is completely mapped.
 
static bool page_table_is_unmapped (page_table_t *table, const void *virtAddr, uint64_t pageAmount)
 Checks if a range of virtual addresses is completely unmapped.
 
static uint64_t page_table_map (page_table_t *table, void *virtAddr, void *physAddr, uint64_t pageAmount, pml_flags_t flags, pml_callback_id_t callbackId)
 Maps a range of virtual addresses to physical addresses in the page table.
 
static uint64_t page_table_map_pages (page_table_t *table, void *virtAddr, void **pages, uint64_t pageAmount, pml_flags_t flags, pml_callback_id_t callbackId)
 Maps an array of physical pages to contiguous virtual addresses in the page table.
 
static void page_table_unmap (page_table_t *table, void *virtAddr, uint64_t pageAmount)
 Unmaps a range of virtual addresses from the page table.
 
static void page_table_page_buffer_push (page_table_t *table, page_table_page_buffer_t *buffer, void *address)
 Pushes a page table level onto the page buffer, freeing the buffer if full.
 
static void page_table_page_buffer_flush (page_table_t *table, page_table_page_buffer_t *buffer)
 Flushes the page buffer, freeing any remaining pages.
 
static void page_table_clear_pml1_pml2_pml3 (page_table_t *table, page_table_traverse_t *prevTraverse, page_table_traverse_t *traverse, page_table_page_buffer_t *pageBuffer)
 Clears any empty page table levels any time a pml1, pml2 or pml3 boundry is crossed.
 
static void page_table_clear (page_table_t *table, void *virtAddr, uint64_t pageAmount)
 Clears page table entries in the specified range and frees any owned pages.
 
static void page_table_collect_callbacks (page_table_t *table, void *virtAddr, uint64_t pageAmount, uint64_t *callbacks)
 Collects the number of pages associated with each callback ID in the specified range.
 
static uint64_t page_table_set_flags (page_table_t *table, void *virtAddr, uint64_t pageAmount, pml_flags_t flags)
 Sets the flags for a range of pages in the page table.
 
static uint64_t page_table_find_unmapped_region (page_table_t *table, void *startAddr, void *endAddr, uint64_t pageAmount, void **outAddr)
 Finds the first contiguous unmapped region with the given number of pages within the specified address range.
 
static bool page_table_is_pinned (page_table_t *table, const void *virtAddr, uint64_t pageAmount)
 Checks if any page in a range is pinned.