pub struct VirtAddr(/* private fields */);
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.
Implementations§
Source§impl VirtAddr
impl VirtAddr
Sourcepub const unsafe fn new_unsafe(addr: u64) -> VirtAddr
pub const unsafe fn new_unsafe(addr: u64) -> VirtAddr
Creates a new address, without any checks.
§Safety
If addr
does not comply with the platforms requirements for
this address type, this can lead to UB in functions relying on
the compliance or when using the requirements.
Source§impl VirtAddr
impl VirtAddr
Sourcepub 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 wether 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).
Sourcepub const fn new_truncate(addr: u64) -> VirtAddr
pub const fn new_truncate(addr: u64) -> VirtAddr
Sourcepub 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
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.
pub const fn as_usize(&self) -> usize
Sourcepub fn is_aligned(self, align: u64) -> bool
pub fn is_aligned(self, align: u64) -> bool
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§
Source§impl AddAssign<u64> for VirtAddr
impl AddAssign<u64> for VirtAddr
Source§fn add_assign(&mut self, rhs: u64)
fn add_assign(&mut self, rhs: u64)
+=
operation. Read moreSource§impl AddAssign<usize> for VirtAddr
impl AddAssign<usize> for VirtAddr
Source§fn add_assign(&mut self, rhs: usize)
fn add_assign(&mut self, rhs: usize)
+=
operation. Read moreSource§impl BitAndAssign<u64> for VirtAddr
impl BitAndAssign<u64> for VirtAddr
Source§fn bitand_assign(&mut self, rhs: u64)
fn bitand_assign(&mut self, rhs: u64)
&=
operation. Read moreSource§impl BitOrAssign<u64> for VirtAddr
impl BitOrAssign<u64> for VirtAddr
Source§fn bitor_assign(&mut self, rhs: u64)
fn bitor_assign(&mut self, rhs: u64)
|=
operation. Read moreSource§impl BitXorAssign<u64> for VirtAddr
impl BitXorAssign<u64> for VirtAddr
Source§fn bitxor_assign(&mut self, rhs: u64)
fn bitxor_assign(&mut self, rhs: u64)
^=
operation. Read moreSource§impl MemoryAddress for VirtAddr
impl MemoryAddress for VirtAddr
Source§impl Ord for VirtAddr
impl Ord for VirtAddr
Source§impl PartialOrd for VirtAddr
impl PartialOrd for VirtAddr
Source§impl ShlAssign<usize> for VirtAddr
impl ShlAssign<usize> for VirtAddr
Source§fn shl_assign(&mut self, rhs: usize)
fn shl_assign(&mut self, rhs: usize)
<<=
operation. Read moreSource§impl ShrAssign<usize> for VirtAddr
impl ShrAssign<usize> for VirtAddr
Source§fn shr_assign(&mut self, rhs: usize)
fn shr_assign(&mut self, rhs: usize)
>>=
operation. Read moreSource§impl SubAssign<u64> for VirtAddr
impl SubAssign<u64> for VirtAddr
Source§fn sub_assign(&mut self, rhs: u64)
fn sub_assign(&mut self, rhs: u64)
-=
operation. Read moreSource§impl SubAssign<usize> for VirtAddr
impl SubAssign<usize> for VirtAddr
Source§fn sub_assign(&mut self, rhs: usize)
fn sub_assign(&mut self, rhs: usize)
-=
operation. Read more