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 AddAssign<usize> for PhysAddr
Available on 64-bit only.
impl AddAssign<usize> for PhysAddr
source§fn add_assign(&mut self, rhs: usize)
fn add_assign(&mut self, rhs: usize)
+=
operation. Read moresource§impl Ord for PhysAddr
impl Ord for PhysAddr
source§impl PartialEq for PhysAddr
impl PartialEq for PhysAddr
source§impl PartialOrd for PhysAddr
impl PartialOrd for PhysAddr
1.0.0 · source§fn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
self
and other
) and is used by the <=
operator. Read moresource§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 moresource§impl SubAssign<usize> for PhysAddr
Available on 64-bit only.
impl SubAssign<usize> for PhysAddr
source§fn sub_assign(&mut self, rhs: usize)
fn sub_assign(&mut self, rhs: usize)
-=
operation. Read more