kmalloc / kfree allocations backed by a contiguous 1 MiB VMM region. Each layer exposes its own API and statistics, and each adds its own hardening measures so that memory bugs are caught as early and as loudly as possible.
User/kernel address-space separation is not yet active in this release (
user_kernel_separation: false). The VMM_USER page flag is defined but the kernel does not switch page tables on any privilege boundary. All execution happens in ring 0 with a single shared address space.Physical Memory (PMM)
Page Size and Identity Map
The PMM works exclusively in 4 KiB (4 096 byte) pages. It builds its free-page bitmap from the total usable RAM figure supplied by your bootloader at entry time. The identity map — where virtual addressV maps to physical address V — covers only the first 1 024 MiB of physical address space. Physical memory above 1 GiB is tracked by the PMM but cannot be accessed through the identity map; you must create explicit VMM mappings for it.
Allocation API
PMM Statistics
pmm_get_stats fills a pmm_stats_t struct with the following counters:
Virtual Memory (VMM)
Paging Model
The VMM implements the standard x86_64 four-level paging hierarchy (PML4 → PDPT → PD → PT). Each leaf entry maps exactly one 4 KiB page. The VMM supports dynamic mapping and unmapping of individual pages at runtime; there is no large-page (2 MiB / 1 GiB) support in this release.Mapping API
Page Flags
Pass a bitwise-OR combination of the constants below as theflags argument to vmm_map_page:
Security Protections
MVH Kernel enables the following hardware security features during VMM initialisation, conditional on CPU support detected via CPUID:Kernel Memory Permissions
Kernel Heap
Overview
The kernel heap occupies a contiguous 1 MiB region of kernel virtual address space and is managed with a coalescing free-list allocator. Adjacent free blocks are merged on everykfree call, keeping fragmentation low over long-running sessions.
Allocation API
Hardening
MVH Kernel’s heap implements three independent hardening layers:1
Canary Protection
Every allocated block stores a magic canary value immediately after the user data. When you call
kfree, the canary is verified before the block is returned to the free list. A mismatched canary means a buffer overrun has occurred and the kernel panics immediately with a descriptive message, rather than silently corrupting later allocations.2
Free Poisoning
After a block is freed its memory is overwritten with a poison byte pattern. Any code that reads from the freed region will see nonsense data, and any code that dereferences a poisoned pointer will quickly fault, making use-after-free bugs detectable at the point of access rather than at a distant, confusing downstream failure.
3
Invalid-Free Tracking
Calls to
kfree with a pointer that was never returned by kmalloc, has already been freed, or falls outside the heap region are counted in the invalid_frees statistics field. The kernel does not silently ignore these calls — each one increments the counter and, depending on severity, can trigger a panic.Heap Statistics
heap_get_stats fills a heap_stats_t struct: