#[repr(transparent)]pub struct VirtAddr(_);
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 criterium
are called “canonical”. This type guarantees that it always represents a canonical address.
Implementations
sourceimpl VirtAddr
impl VirtAddr
sourcepub fn new(addr: u64) -> VirtAddr
pub fn new(addr: u64) -> VirtAddr
Creates a new canonical virtual address.
This function performs sign extension of bit 47 to make the address canonical.
Panics
This function panics if the bits in the range 48 to 64 contain data (i.e. are not null and no sign extension).
sourcepub fn try_new(addr: u64) -> Result<VirtAddr, VirtAddrNotValid>
pub fn try_new(addr: u64) -> Result<VirtAddr, VirtAddrNotValid>
Tries to create a new canonical virtual address.
This function tries to performs sign extension of bit 47 to make the address canonical. It succeeds if bits 48 to 64 are either a correct sign extension (i.e. copies of bit 47) or all null. Else, an error is returned.
sourcepub const fn new_truncate(addr: u64) -> VirtAddr
pub const fn new_truncate(addr: u64) -> VirtAddr
Creates a new canonical virtual address, throwing out bits 48..64.
This function performs sign extension of bit 47 to make the address canonical, so
bits 48 to 64 are overwritten. If you want to check that these bits contain no data,
use new
or try_new
.
sourcepub 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.
sourcepub 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.
sourcepub const fn is_null(self) -> bool
pub const fn is_null(self) -> bool
Convenience method for checking if a virtual address is null.
sourcepub fn align_up<U>(self, align: U) -> Self where
U: Into<u64>,
pub fn align_up<U>(self, align: U) -> Self where
U: Into<u64>,
Aligns the virtual address upwards to the given alignment.
See the align_up
function for more information.
sourcepub fn align_down<U>(self, align: U) -> Self where
U: Into<u64>,
pub fn align_down<U>(self, align: U) -> Self where
U: Into<u64>,
Aligns the virtual address downwards to the given alignment.
See the align_down
function for more information.
sourcepub fn is_aligned<U>(self, align: U) -> bool where
U: Into<u64>,
pub fn is_aligned<U>(self, align: U) -> bool where
U: Into<u64>,
Checks whether the virtual address has the demanded alignment.
sourcepub const fn page_offset(self) -> PageOffset
pub const fn page_offset(self) -> PageOffset
Returns the 12-bit page offset of this virtual address.
sourcepub const fn p1_index(self) -> PageTableIndex
pub const fn p1_index(self) -> PageTableIndex
Returns the 9-bit level 1 page table index.
sourcepub const fn p2_index(self) -> PageTableIndex
pub const fn p2_index(self) -> PageTableIndex
Returns the 9-bit level 2 page table index.
sourcepub const fn p3_index(self) -> PageTableIndex
pub const fn p3_index(self) -> PageTableIndex
Returns the 9-bit level 3 page table index.
sourcepub const fn p4_index(self) -> PageTableIndex
pub const fn p4_index(self) -> PageTableIndex
Returns the 9-bit level 4 page table index.
sourcepub 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
sourceimpl AddAssign<u64> for VirtAddr
impl AddAssign<u64> for VirtAddr
sourcefn add_assign(&mut self, rhs: u64)
fn add_assign(&mut self, rhs: u64)
Performs the +=
operation. Read more
sourceimpl AddAssign<usize> for VirtAddr
impl AddAssign<usize> for VirtAddr
sourcefn add_assign(&mut self, rhs: usize)
fn add_assign(&mut self, rhs: usize)
Performs the +=
operation. Read more
sourceimpl Ord for VirtAddr
impl Ord for VirtAddr
sourceimpl PartialOrd<VirtAddr> for VirtAddr
impl PartialOrd<VirtAddr> for VirtAddr
sourcefn partial_cmp(&self, other: &VirtAddr) -> Option<Ordering>
fn partial_cmp(&self, other: &VirtAddr) -> Option<Ordering>
This method returns an ordering between self
and other
values if one exists. Read more
1.0.0 · sourcefn lt(&self, other: &Rhs) -> bool
fn lt(&self, other: &Rhs) -> bool
This method tests less than (for self
and other
) and is used by the <
operator. Read more
1.0.0 · sourcefn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
This method tests less than or equal to (for self
and other
) and is used by the <=
operator. Read more
sourceimpl Step for VirtAddr
impl Step for VirtAddr
sourcefn steps_between(start: &Self, end: &Self) -> Option<usize>
fn steps_between(start: &Self, end: &Self) -> Option<usize>
step_trait
)Returns the number of successor steps required to get from start
to end
. Read more
sourcefn forward_checked(start: Self, count: usize) -> Option<Self>
fn forward_checked(start: Self, count: usize) -> Option<Self>
step_trait
)Returns the value that would be obtained by taking the successor
of self
count
times. Read more
sourcefn backward_checked(start: Self, count: usize) -> Option<Self>
fn backward_checked(start: Self, count: usize) -> Option<Self>
step_trait
)Returns the value that would be obtained by taking the predecessor
of self
count
times. Read more
sourcefn forward(start: Self, count: usize) -> Self
fn forward(start: Self, count: usize) -> Self
step_trait
)Returns the value that would be obtained by taking the successor
of self
count
times. Read more
sourceunsafe fn forward_unchecked(start: Self, count: usize) -> Self
unsafe fn forward_unchecked(start: Self, count: usize) -> Self
step_trait
)Returns the value that would be obtained by taking the successor
of self
count
times. Read more
sourcefn backward(start: Self, count: usize) -> Self
fn backward(start: Self, count: usize) -> Self
step_trait
)Returns the value that would be obtained by taking the predecessor
of self
count
times. Read more
sourceunsafe fn backward_unchecked(start: Self, count: usize) -> Self
unsafe fn backward_unchecked(start: Self, count: usize) -> Self
step_trait
)Returns the value that would be obtained by taking the predecessor
of self
count
times. Read more
sourceimpl SubAssign<u64> for VirtAddr
impl SubAssign<u64> for VirtAddr
sourcefn sub_assign(&mut self, rhs: u64)
fn sub_assign(&mut self, rhs: u64)
Performs the -=
operation. Read more
sourceimpl SubAssign<usize> for VirtAddr
impl SubAssign<usize> for VirtAddr
sourcefn sub_assign(&mut self, rhs: usize)
fn sub_assign(&mut self, rhs: usize)
Performs the -=
operation. Read more
impl Copy for VirtAddr
impl Eq for VirtAddr
impl StructuralEq for VirtAddr
impl StructuralPartialEq for VirtAddr
Auto Trait Implementations
impl RefUnwindSafe for VirtAddr
impl Send for VirtAddr
impl Sync for VirtAddr
impl Unpin for VirtAddr
impl UnwindSafe for VirtAddr
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more