From a64d67237c73474e8db46ca5f0df22a0626343ee Mon Sep 17 00:00:00 2001 From: Matthew Leach Date: Fri, 8 May 2026 11:07:24 +0100 Subject: [PATCH] libkernel: address: add virtualisation guest types Add address types for use in virtualised environments. --- libkernel/src/memory/address.rs | 14 ++++++++++++++ libkernel/src/memory/region.rs | 8 +++++--- 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/libkernel/src/memory/address.rs b/libkernel/src/memory/address.rs index e0d1442..8c86836 100644 --- a/libkernel/src/memory/address.rs +++ b/libkernel/src/memory/address.rs @@ -57,16 +57,22 @@ pub struct Virtual; #[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord)] pub struct Physical; +/// Marker for a physical guest memory address type. +#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord)] +pub struct GuestPhysical; + /// Marker for user memory address type. #[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord)] pub struct User; impl sealed::Sealed for Virtual {} impl sealed::Sealed for Physical {} +impl sealed::Sealed for GuestPhysical {} impl sealed::Sealed for User {} impl MemKind for Virtual {} impl MemKind for Physical {} +impl MemKind for GuestPhysical {} impl MemKind for User {} /// A memory address with a kind (`Virtual`, `Physical`, or `User`) and an @@ -189,6 +195,10 @@ pub type TPA = Address; pub type TVA = Address; /// A typed user address. pub type TUA = Address; +/// A typed guest physical address. +pub type TGPA = Address; +/// A typed host physical address. +pub type THPA = TPA; /// An untyped physical address. pub type PA = Address; @@ -196,6 +206,10 @@ pub type PA = Address; pub type VA = Address; /// An untyped user address. pub type UA = Address; +/// An untyped guest physical address. +pub type GPA = Address; +/// An untyped host physical address. +pub type HPA = PA; impl TPA { /// Convert to a raw const pointer. diff --git a/libkernel/src/memory/region.rs b/libkernel/src/memory/region.rs index e40abd1..0d51215 100644 --- a/libkernel/src/memory/region.rs +++ b/libkernel/src/memory/region.rs @@ -31,7 +31,7 @@ use super::{ PAGE_SHIFT, PAGE_SIZE, - address::{Address, AddressTranslator, MemKind, Physical, User, Virtual}, + address::{Address, AddressTranslator, GuestPhysical, MemKind, Physical, User, Virtual}, page::PageFrame, }; @@ -251,8 +251,7 @@ impl MemoryRegion { } /// Increases the capacity of the region by size bytes. - #[cfg(feature = "proc_vm")] - pub(crate) fn expand_by(&mut self, size: usize) { + pub fn expand_by(&mut self, size: usize) { assert!(size & crate::memory::PAGE_MASK == 0); self.size += size; @@ -414,6 +413,9 @@ impl VirtMemoryRegion { /// A memory region of user-space addresses. pub type UserMemoryRegion = MemoryRegion; +/// A memory region of guest-physical memory. +pub type GuestPhysMemoryRegion = MemoryRegion; + /// A representation of a `MemoryRegion` that has been expanded to be page-aligned. /// /// This struct holds the new, larger, page-aligned region, as well as the