pub struct PhysFrame<S: PageSize = Size4KiB> { /* private fields */ }Expand description
A physical memory frame.
Implementations§
Source§impl<S: PageSize> PhysFrame<S>
impl<S: PageSize> PhysFrame<S>
Sourcepub const fn from_start_address(
address: PhysAddr,
) -> Result<Self, AddressNotAligned>
pub const fn from_start_address( address: PhysAddr, ) -> Result<Self, AddressNotAligned>
Returns the frame that starts at the given virtual address.
Returns an error if the address is not correctly aligned (i.e. is not a valid frame start).
Sourcepub const unsafe fn from_start_address_unchecked(
start_address: PhysAddr,
) -> Self
pub const unsafe fn from_start_address_unchecked( start_address: PhysAddr, ) -> Self
Returns the frame that starts at the given virtual address.
§Safety
The address must be correctly aligned.
Sourcepub const fn from_pfn(pfn: u64) -> Self
pub const fn from_pfn(pfn: u64) -> Self
Returns the frame by a physical frame number.
use x86_64::{PhysAddr, structures::paging::{PhysFrame, Size4KiB}};
assert_eq!(PhysFrame::<Size4KiB>::from_pfn(0x123), PhysFrame::<Size4KiB>::containing_address(PhysAddr::new(0x123000)));§Panics
This function will panic if the resulting address is not valid.
Sourcepub const fn try_from_pfn(pfn: u64) -> Result<Self, PfnNotValid>
pub const fn try_from_pfn(pfn: u64) -> Result<Self, PfnNotValid>
Returns the frame by a physical frame number.
use x86_64::{PhysAddr, structures::paging::{PhysFrame, Size4KiB}};
assert_eq!(PhysFrame::<Size4KiB>::try_from_pfn(0x123), Ok(PhysFrame::<Size4KiB>::containing_address(PhysAddr::new(0x123000))));§Error
This function will return an error if the resulting address is not valid.
Sourcepub const unsafe fn from_pfn_unchecked(pfn: u64) -> Self
pub const unsafe fn from_pfn_unchecked(pfn: u64) -> Self
Sourcepub const fn containing_address(address: PhysAddr) -> Self
pub const fn containing_address(address: PhysAddr) -> Self
Returns the frame that contains the given physical address.
Sourcepub const fn start_address(self) -> PhysAddr
pub const fn start_address(self) -> PhysAddr
Returns the start address of the frame.
Sourcepub const fn pfn(self) -> u64
pub const fn pfn(self) -> u64
Returns the PFN of the current frame.
The PFN is defined to be the address divided by the page size.
use x86_64::{PhysAddr, structures::paging::{PhysFrame, Size1GiB, Size2MiB, Size4KiB}};
assert_eq!(PhysFrame::<Size4KiB>::containing_address(PhysAddr::new(0x123000)).pfn(), 0x123);
// Note that this means that the PFN for the same address will be
// different for different page sizes.
assert_eq!(PhysFrame::<Size4KiB>::containing_address(PhysAddr::new(0xC000_0000)).pfn(), 0xC0000);
assert_eq!(PhysFrame::<Size2MiB>::containing_address(PhysAddr::new(0xC000_0000)).pfn(), 0x600);
assert_eq!(PhysFrame::<Size1GiB>::containing_address(PhysAddr::new(0xC000_0000)).pfn(), 0x3);Sourcepub const fn range(start: PhysFrame<S>, end: PhysFrame<S>) -> PhysFrameRange<S> ⓘ
pub const fn range(start: PhysFrame<S>, end: PhysFrame<S>) -> PhysFrameRange<S> ⓘ
Returns a range of frames, exclusive end.
Sourcepub const fn range_inclusive(
start: PhysFrame<S>,
end: PhysFrame<S>,
) -> PhysFrameRangeInclusive<S> ⓘ
pub const fn range_inclusive( start: PhysFrame<S>, end: PhysFrame<S>, ) -> PhysFrameRangeInclusive<S> ⓘ
Returns a range of frames, inclusive end.
Trait Implementations§
Source§impl<S: PageSize> AddAssign<u64> for PhysFrame<S>
impl<S: PageSize> AddAssign<u64> for PhysFrame<S>
Source§fn add_assign(&mut self, rhs: u64)
fn add_assign(&mut self, rhs: u64)
+= operation. Read moreimpl<S: Copy + PageSize> Copy for PhysFrame<S>
impl<S: Eq + PageSize> Eq for PhysFrame<S>
Source§impl<S: Ord + PageSize> Ord for PhysFrame<S>
impl<S: Ord + PageSize> Ord for PhysFrame<S>
1.21.0 (const: unstable)§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
Source§impl<S: PartialOrd + PageSize> PartialOrd for PhysFrame<S>
impl<S: PartialOrd + PageSize> PartialOrd for PhysFrame<S>
impl<S: PartialEq + PageSize> StructuralPartialEq for PhysFrame<S>
Auto Trait Implementations§
impl<S> Freeze for PhysFrame<S>
impl<S> RefUnwindSafe for PhysFrame<S>where
S: RefUnwindSafe,
impl<S> Send for PhysFrame<S>where
S: Send,
impl<S> Sync for PhysFrame<S>where
S: Sync,
impl<S> Unpin for PhysFrame<S>where
S: Unpin,
impl<S> UnsafeUnpin for PhysFrame<S>
impl<S> UnwindSafe for PhysFrame<S>where
S: UnwindSafe,
Blanket Implementations§
§impl<T> Any for Twhere
T: 'static + ?Sized,
impl<T> Any for Twhere
T: 'static + ?Sized,
§impl<T> Borrow<T> for Twhere
T: ?Sized,
impl<T> Borrow<T> for Twhere
T: ?Sized,
§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§unsafe fn clone_to_uninit(&self, dest: *mut u8)
unsafe fn clone_to_uninit(&self, dest: *mut u8)
clone_to_uninit)