Skip to main content

PageFrame

Struct PageFrame 

Source
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

Source

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);
Source

pub const fn single_page(addr: PhysAddr) -> Self

Creates a page frame for a single page.

§Arguments
  • addr - The physical address of the page.
§Examples
use ruvix_physmem::{PageFrame, PhysAddr};

let frame = PageFrame::single_page(PhysAddr::new(0x1000));
assert_eq!(frame.pages(), 1);
assert_eq!(frame.order().as_usize(), 0);
Source

pub const fn addr(&self) -> PhysAddr

Returns the physical address of the frame’s start.

Source

pub const fn order(&self) -> PageOrder

Returns the order of the frame.

Source

pub const fn pages(&self) -> usize

Returns the number of pages in the frame.

Source

pub const fn bytes(&self) -> usize

Returns the size of the frame in bytes.

Source

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*0x1000
Source

pub const fn pfn(&self) -> u64

Returns the page frame number of the first page.

Source

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)));
Source

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);
}
Source

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);
Source

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§

Source§

impl Clone for PageFrame

Source§

fn clone(&self) -> PageFrame

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for PageFrame

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Display for PageFrame

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Hash for PageFrame

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl PartialEq for PageFrame

Source§

fn eq(&self, other: &PageFrame) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Copy for PageFrame

Source§

impl Eq for PageFrame

Source§

impl StructuralPartialEq for PageFrame

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.