# ahrightos-memory
`ahrightos-memory` contains the portable memory-management primitives used by
the AhRightOS teaching kernel: address wrappers, Sv39 page-table entries, page
tables, physical frames, and the simple frame allocator.
The crate is `no_std` outside tests and is designed to be consumed by the
RISC-V kernel crate as well as by host-side unit and integration tests.
## Incremental VM contracts
The portable crate now includes a small, testable virtual-memory region model:
- `VmRegion` describes an mmap-like virtual range, permissions, and kind
(`Anonymous`, `FileBacked`, grow-down `Stack`, `SwapBacked`).
- `VmRegionTable` rejects overlapping regions, finds regions by fault address,
tracks lazy per-page commitment with a bounded bitmap, and can grow stack
reservations down within a configured maximum.
- This is intentionally bookkeeping only. Actual page-fault dispatch, file
page-in, and swap I/O remain kernel integration steps, but the invariants are
now enforced in a host-testable `no_std` component.
```mermaid
flowchart LR
Kernel[ahrightos-kernel] --> Memory[ahrightos-memory]
Memory --> Addr[VirtAddr / PhysAddr]
Memory --> PageTable[PageTable / PageTableEntry]
Memory --> Alloc[SimpleFrameAllocator]
Memory --> VM[VmRegion / VmRegionTable]
```