Struct VirtAddr
#[repr(transparent)]pub struct VirtAddr(u64);Expand description
A canonical 64-bit virtual 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 48 lower bits of a virtual address can be used. The top 16 bits need
to be copies of bit 47, i.e. the most significant bit. Addresses that fulfil this criterion
are called “canonical”. This type guarantees that it always represents a canonical address.
Tuple Fields§
§0: u64Implementations§
§impl VirtAddr
impl VirtAddr
pub const fn try_new(addr: u64) -> Result<VirtAddr, VirtAddrNotValid>
pub const fn try_new(addr: u64) -> Result<VirtAddr, VirtAddrNotValid>
Tries to create a new canonical virtual address.
This function checks whether the given address is canonical and returns an error otherwise. An address is canonical if bits 48 to 64 are a correct sign extension (i.e. copies of bit 47).
pub const fn new_truncate(addr: u64) -> VirtAddr
pub const fn new_truncate(addr: u64) -> VirtAddr
pub const unsafe fn new_unsafe(addr: u64) -> VirtAddr
pub const unsafe fn new_unsafe(addr: u64) -> VirtAddr
Creates a new virtual address, without any checks.
§Safety
You must make sure bits 48..64 are equal to bit 47. This is not checked.
pub fn from_ptr<T>(ptr: *const T) -> VirtAddrwhere
T: ?Sized,
pub fn from_ptr<T>(ptr: *const T) -> VirtAddrwhere
T: ?Sized,
Creates a virtual address from the given pointer
pub const fn as_mut_ptr<T>(self) -> *mut T
pub const fn as_mut_ptr<T>(self) -> *mut T
Converts the address to a mutable raw pointer.
pub fn align_up<U>(self, align: U) -> VirtAddr
pub fn align_up<U>(self, align: U) -> VirtAddr
Aligns the virtual address upwards to the given alignment.
See the align_up function for more information.
§Panics
This function panics if the resulting address is higher than
0xffff_ffff_ffff_ffff.
pub fn align_down<U>(self, align: U) -> VirtAddr
pub fn align_down<U>(self, align: U) -> VirtAddr
Aligns the virtual address downwards to the given alignment.
See the align_down function for more information.
pub fn is_aligned<U>(self, align: U) -> bool
pub fn is_aligned<U>(self, align: U) -> bool
Checks whether the virtual address has the demanded alignment.
pub const fn page_offset(self) -> PageOffset
pub const fn page_offset(self) -> PageOffset
Returns the 12-bit page offset of this virtual address.
pub const fn p1_index(self) -> PageTableIndex
pub const fn p1_index(self) -> PageTableIndex
Returns the 9-bit level 1 page table index.
pub const fn p2_index(self) -> PageTableIndex
pub const fn p2_index(self) -> PageTableIndex
Returns the 9-bit level 2 page table index.
pub const fn p3_index(self) -> PageTableIndex
pub const fn p3_index(self) -> PageTableIndex
Returns the 9-bit level 3 page table index.
pub const fn p4_index(self) -> PageTableIndex
pub const fn p4_index(self) -> PageTableIndex
Returns the 9-bit level 4 page table index.
pub const fn page_table_index(self, level: PageTableLevel) -> PageTableIndex
pub const fn page_table_index(self, level: PageTableLevel) -> PageTableIndex
Returns the 9-bit level page table index.
Trait Implementations§
§impl Add<u64> for VirtAddr
impl Add<u64> for VirtAddr
§fn add(self, rhs: u64) -> <VirtAddr as Add<u64>>::Output
fn add(self, rhs: u64) -> <VirtAddr as Add<u64>>::Output
Add an offset to a virtual address.
This function performs normal arithmetic addition and doesn’t jump the
address gap. If you’re looking for a successor operation that jumps the
address gap, use Step::forward.
§Panics
This function will panic on overflow or if the result is not a canonical address.
§impl AddAssign<u64> for VirtAddr
impl AddAssign<u64> for VirtAddr
§fn add_assign(&mut self, rhs: u64)
fn add_assign(&mut self, rhs: u64)
Add an offset to a virtual address.
This function performs normal arithmetic addition and doesn’t jump the
address gap. If you’re looking for a successor operation that jumps the
address gap, use Step::forward.
§Panics
This function will panic on overflow or if the result is not a canonical address.
impl Copy for VirtAddr
impl Eq for VirtAddr
§impl Ord for VirtAddr
impl Ord for VirtAddr
1.21.0 (const: unstable) · Source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
§impl PartialOrd for VirtAddr
impl PartialOrd for VirtAddr
§impl Step for VirtAddr
Available on crate feature step_trait only.
impl Step for VirtAddr
step_trait only.§fn steps_between(start: &VirtAddr, end: &VirtAddr) -> (usize, Option<usize>)
fn steps_between(start: &VirtAddr, end: &VirtAddr) -> (usize, Option<usize>)
step_trait)start to end
like Iterator::size_hint(). Read more§fn forward_checked(start: VirtAddr, count: usize) -> Option<VirtAddr>
fn forward_checked(start: VirtAddr, count: usize) -> Option<VirtAddr>
step_trait)§fn backward_checked(start: VirtAddr, count: usize) -> Option<VirtAddr>
fn backward_checked(start: VirtAddr, count: usize) -> Option<VirtAddr>
step_trait)§fn forward_overflowing(start: VirtAddr, count: usize) -> (VirtAddr, bool)
fn forward_overflowing(start: VirtAddr, count: usize) -> (VirtAddr, bool)
step_trait)self count times along with a boolean tracking whether overflow
occurred. Read more§fn backward_overflowing(start: VirtAddr, count: usize) -> (VirtAddr, bool)
fn backward_overflowing(start: VirtAddr, count: usize) -> (VirtAddr, bool)
step_trait)self count times along with a boolean tracking whether overflow
occurred. Read moreSource§fn forward(start: Self, count: usize) -> Self
fn forward(start: Self, count: usize) -> Self
step_trait)Source§unsafe fn forward_unchecked(start: Self, count: usize) -> Self
unsafe fn forward_unchecked(start: Self, count: usize) -> Self
step_trait)Source§fn backward(start: Self, count: usize) -> Self
fn backward(start: Self, count: usize) -> Self
step_trait)Source§unsafe fn backward_unchecked(start: Self, count: usize) -> Self
unsafe fn backward_unchecked(start: Self, count: usize) -> Self
step_trait)impl StructuralPartialEq for VirtAddr
§impl Sub<u64> for VirtAddr
impl Sub<u64> for VirtAddr
§fn sub(self, rhs: u64) -> <VirtAddr as Sub<u64>>::Output
fn sub(self, rhs: u64) -> <VirtAddr as Sub<u64>>::Output
Subtract an offset from a virtual address.
This function performs normal arithmetic subtraction and doesn’t jump
the address gap. If you’re looking for a predecessor operation that
jumps the address gap, use Step::backward.
§Panics
This function will panic on overflow or if the result is not a canonical address.
§impl SubAssign<u64> for VirtAddr
impl SubAssign<u64> for VirtAddr
§fn sub_assign(&mut self, rhs: u64)
fn sub_assign(&mut self, rhs: u64)
Subtract an offset from a virtual address.
This function performs normal arithmetic subtraction and doesn’t jump
the address gap. If you’re looking for a predecessor operation that
jumps the address gap, use Step::backward.
§Panics
This function will panic on overflow or if the result is not a canonical address.
Auto Trait Implementations§
impl Freeze for VirtAddr
impl RefUnwindSafe for VirtAddr
impl Send for VirtAddr
impl Sync for VirtAddr
impl Unpin for VirtAddr
impl UnsafeUnpin for VirtAddr
impl UnwindSafe for VirtAddr
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§impl<Q, K> Comparable<K> for Q
impl<Q, K> Comparable<K> for Q
§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more