pub struct PhysAddr(/* private fields */);
Expand description
A 64-bit physical memory address.
This is a wrapper type around an u64
, so it is always 8 bytes, even when compiled
on non 64-bit systems. The
TryFrom
trait can be used for performing conversions
between u64
and usize
.
On x86_64
, only the 52 lower bits of a physical address can be used. The top 12 bits need
to be zero. This type guarantees that it always represents a valid physical address.
Implementations§
Source§impl PhysAddr
impl PhysAddr
Sourcepub const fn new_truncate(addr: u64) -> PhysAddr
pub const fn new_truncate(addr: u64) -> PhysAddr
Creates a new physical address, throwing bits 52..64 away.
Sourcepub const unsafe fn new_unsafe(addr: u64) -> PhysAddr
pub const unsafe fn new_unsafe(addr: u64) -> PhysAddr
Creates a new physical address, without any checks.
§Safety
You must make sure bits 52..64 are zero. This is not checked.
Sourcepub const fn try_new(addr: u64) -> Result<Self, PhysAddrNotValid>
pub const fn try_new(addr: u64) -> Result<Self, PhysAddrNotValid>
Tries to create a new physical address.
Fails if any bits in the range 52 to 64 are set.
Sourcepub const fn is_null(self) -> bool
pub const fn is_null(self) -> bool
Convenience method for checking if a physical address is null.
Sourcepub fn align_up<U>(self, align: U) -> Self
pub fn align_up<U>(self, align: U) -> Self
Aligns the physical address upwards to the given alignment.
See the align_up
function for more information.
§Panics
This function panics if the resulting address has a bit in the range 52 to 64 set.
Sourcepub fn align_down<U>(self, align: U) -> Self
pub fn align_down<U>(self, align: U) -> Self
Aligns the physical address downwards to the given alignment.
See the align_down
function for more information.
Sourcepub fn is_aligned<U>(self, align: U) -> bool
pub fn is_aligned<U>(self, align: U) -> bool
Checks whether the physical address has the demanded alignment.
Trait Implementations§
Source§impl AddAssign<u64> for PhysAddr
impl AddAssign<u64> for PhysAddr
Source§fn add_assign(&mut self, rhs: u64)
fn add_assign(&mut self, rhs: u64)
+=
operation. Read moreSource§impl Ord for PhysAddr
impl Ord for PhysAddr
Source§impl PartialOrd for PhysAddr
impl PartialOrd for PhysAddr
Source§impl SubAssign<u64> for PhysAddr
impl SubAssign<u64> for PhysAddr
Source§fn sub_assign(&mut self, rhs: u64)
fn sub_assign(&mut self, rhs: u64)
-=
operation. Read more