mirror of
https://github.com/hexagonal-sun/moss-kernel.git
synced 2025-12-23 22:47:55 -05:00
libkernel: address: ensure to_pfn can only be called on PA
calculating a PFN from a VA makes no sense since it could be mapped to any address. Therefore, ensure that it can *only* be called on PAs.
This commit is contained in:
committed by
Ashwin Naren
parent
264d603044
commit
bebee6d8f5
@@ -164,10 +164,6 @@ impl<K: MemKind, T> Address<K, T> {
|
||||
pub fn is_null(self) -> bool {
|
||||
self.inner == 0
|
||||
}
|
||||
|
||||
pub fn to_pfn(&self) -> PageFrame {
|
||||
PageFrame::from_pfn(self.inner >> PAGE_SHIFT)
|
||||
}
|
||||
}
|
||||
|
||||
impl<K: MemKind, T: Sized> Address<K, T> {
|
||||
@@ -294,6 +290,10 @@ impl PA {
|
||||
pub fn cast<T>(self) -> TPA<T> {
|
||||
TPA::from_value(self.value())
|
||||
}
|
||||
|
||||
pub fn to_pfn(&self) -> PageFrame {
|
||||
PageFrame::from_pfn(self.inner >> PAGE_SHIFT)
|
||||
}
|
||||
}
|
||||
|
||||
/// Trait for translating between physical and virtual addresses.
|
||||
|
||||
@@ -79,8 +79,10 @@ impl<A: CpuOps, G: PageAllocGetter<A>, T: AddressTranslator<()>> ClaimedPage<A,
|
||||
|
||||
/// Takes ownership of the page at pfn.
|
||||
///
|
||||
/// SAFETY: Ensure that the calling context does indeed own this page.
|
||||
/// Otherwise, the page may be free'd when it's owned by another context.
|
||||
/// # Safety
|
||||
///
|
||||
/// Ensure that the calling context does indeed own this page. Otherwise,
|
||||
/// the page may be free'd when it's owned by another context.
|
||||
pub unsafe fn from_pfn(pfn: PageFrame) -> Self {
|
||||
Self(
|
||||
unsafe {
|
||||
|
||||
@@ -372,6 +372,16 @@ impl<T: MemKind> MemoryRegion<T> {
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
/// A memory region in physical address space.
|
||||
pub type PhysMemoryRegion = MemoryRegion<Physical>;
|
||||
|
||||
impl PhysMemoryRegion {
|
||||
/// Map the physical region to virtual space using a translator.
|
||||
pub fn map_via<T: AddressTranslator<()>>(self) -> VirtMemoryRegion {
|
||||
VirtMemoryRegion::new(self.address.to_va::<T>(), self.size)
|
||||
}
|
||||
|
||||
pub fn iter_pfns(self) -> impl Iterator<Item = PageFrame> {
|
||||
let mut count = 0;
|
||||
@@ -391,16 +401,6 @@ impl<T: MemKind> MemoryRegion<T> {
|
||||
}
|
||||
}
|
||||
|
||||
/// A memory region in physical address space.
|
||||
pub type PhysMemoryRegion = MemoryRegion<Physical>;
|
||||
|
||||
impl PhysMemoryRegion {
|
||||
/// Map the physical region to virtual space using a translator.
|
||||
pub fn map_via<T: AddressTranslator<()>>(self) -> VirtMemoryRegion {
|
||||
VirtMemoryRegion::new(self.address.to_va::<T>(), self.size)
|
||||
}
|
||||
}
|
||||
|
||||
/// A memory region in virtual address space.
|
||||
pub type VirtMemoryRegion = MemoryRegion<Virtual>;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user