pub struct PageFrame { /* private fields */ }Expand description
A physical page frame.
Represents a contiguous block of physical memory with a specific physical address and order (size).
§Examples
use ruvix_physmem::{PageFrame, PhysAddr, PageOrder};
let frame = PageFrame::new(PhysAddr::new(0x1000), PageOrder::new(2).unwrap());
assert_eq!(frame.addr().as_u64(), 0x1000);
assert_eq!(frame.pages(), 4);
assert_eq!(frame.bytes(), 16384);Implementations§
Source§impl PageFrame
impl PageFrame
Sourcepub const fn new(addr: PhysAddr, order: PageOrder) -> Self
pub const fn new(addr: PhysAddr, order: PageOrder) -> Self
Creates a new page frame.
§Arguments
addr- The physical address of the frame’s start.order- The order determining the frame’s size.
§Examples
use ruvix_physmem::{PageFrame, PhysAddr, PageOrder};
let frame = PageFrame::new(
PhysAddr::new(0x1000_0000),
PageOrder::new(3).unwrap()
);
assert_eq!(frame.pages(), 8);Sourcepub const fn single_page(addr: PhysAddr) -> Self
pub const fn single_page(addr: PhysAddr) -> Self
Sourcepub const fn end_addr(&self) -> PhysAddr
pub const fn end_addr(&self) -> PhysAddr
Returns the physical address of the frame’s end (exclusive).
§Examples
use ruvix_physmem::{PageFrame, PhysAddr, PageOrder};
let frame = PageFrame::new(
PhysAddr::new(0x1000),
PageOrder::new(2).unwrap()
);
assert_eq!(frame.end_addr().as_u64(), 0x5000); // 0x1000 + 4*0x1000Sourcepub const fn contains(&self, addr: PhysAddr) -> bool
pub const fn contains(&self, addr: PhysAddr) -> bool
Checks if an address is contained within this frame.
§Arguments
addr- The address to check.
§Examples
use ruvix_physmem::{PageFrame, PhysAddr, PageOrder};
let frame = PageFrame::new(
PhysAddr::new(0x1000),
PageOrder::new(2).unwrap() // 4 pages: 0x1000..0x5000
);
assert!(frame.contains(PhysAddr::new(0x1000)));
assert!(frame.contains(PhysAddr::new(0x2500)));
assert!(frame.contains(PhysAddr::new(0x4FFF)));
assert!(!frame.contains(PhysAddr::new(0x5000)));
assert!(!frame.contains(PhysAddr::new(0x0FFF)));Sourcepub const fn split(&self) -> Option<(Self, Self)>
pub const fn split(&self) -> Option<(Self, Self)>
Splits the frame into two buddy frames of the next lower order.
Returns None if the frame is already at the minimum order.
§Examples
use ruvix_physmem::{PageFrame, PhysAddr, PageOrder};
let frame = PageFrame::new(
PhysAddr::new(0x1000),
PageOrder::new(2).unwrap() // 4 pages
);
if let Some((left, right)) = frame.split() {
assert_eq!(left.pages(), 2);
assert_eq!(right.pages(), 2);
assert_eq!(left.addr().as_u64(), 0x1000);
assert_eq!(right.addr().as_u64(), 0x3000);
}Sourcepub const fn buddy_addr(&self) -> PhysAddr
pub const fn buddy_addr(&self) -> PhysAddr
Returns the buddy address for this frame.
The buddy is the adjacent block of the same size that can be merged with this block to form a larger block.
§Examples
use ruvix_physmem::{PageFrame, PhysAddr, PageOrder};
// Frame at 0x1000, order 1 (2 pages)
let frame = PageFrame::new(
PhysAddr::new(0x1000),
PageOrder::new(1).unwrap()
);
// Buddy is at 0x3000 (XOR with block size)
assert_eq!(frame.buddy_addr().as_u64(), 0x3000);
// Frame at 0x3000, order 1 (2 pages)
let frame = PageFrame::new(
PhysAddr::new(0x3000),
PageOrder::new(1).unwrap()
);
// Buddy is at 0x1000
assert_eq!(frame.buddy_addr().as_u64(), 0x1000);Sourcepub const fn merge(&self, buddy: &Self) -> Option<Self>
pub const fn merge(&self, buddy: &Self) -> Option<Self>
Merges this frame with its buddy to create a larger frame.
Returns None if the merge would exceed the maximum order.
§Arguments
buddy- The buddy frame to merge with.
§Examples
use ruvix_physmem::{PageFrame, PhysAddr, PageOrder};
let left = PageFrame::new(PhysAddr::new(0x1000), PageOrder::new(1).unwrap());
let right = PageFrame::new(PhysAddr::new(0x3000), PageOrder::new(1).unwrap());
if let Some(merged) = left.merge(&right) {
assert_eq!(merged.pages(), 4);
assert_eq!(merged.addr().as_u64(), 0x1000);
}Trait Implementations§
impl Copy for PageFrame
impl Eq for PageFrame
impl StructuralPartialEq for PageFrame
Auto Trait Implementations§
impl Freeze for PageFrame
impl RefUnwindSafe for PageFrame
impl Send for PageFrame
impl Sync for PageFrame
impl Unpin for PageFrame
impl UnsafeUnpin for PageFrame
impl UnwindSafe for PageFrame
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more