Struct x86_64::addr::VirtAddr[][src]

#[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

impl VirtAddr[src]

pub fn new(addr: u64) -> VirtAddr[src]

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).

pub fn try_new(addr: u64) -> Result<VirtAddr, VirtAddrNotValid>[src]

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.

pub const fn new_truncate(addr: u64) -> VirtAddr[src]

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.

pub const unsafe fn new_unsafe(addr: u64) -> VirtAddr[src]

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 const fn zero() -> VirtAddr[src]

Creates a virtual address that points to 0.

pub const fn as_u64(self) -> u64[src]

Converts the address to an u64.

pub fn from_ptr<T>(ptr: *const T) -> Self[src]

Creates a virtual address from the given pointer

pub fn as_ptr<T>(self) -> *const T[src]

Converts the address to a raw pointer.

pub fn as_mut_ptr<T>(self) -> *mut T[src]

Converts the address to a mutable raw pointer.

pub const fn is_null(self) -> bool[src]

Convenience method for checking if a virtual address is null.

pub fn align_up<U>(self, align: U) -> Self where
    U: Into<u64>, 
[src]

Aligns the virtual address upwards to the given alignment.

See the align_up function for more information.

pub fn align_down<U>(self, align: U) -> Self where
    U: Into<u64>, 
[src]

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 where
    U: Into<u64>, 
[src]

Checks whether the virtual address has the demanded alignment.

pub const fn page_offset(self) -> PageOffset[src]

Returns the 12-bit page offset of this virtual address.

pub const fn p1_index(self) -> PageTableIndex[src]

Returns the 9-bit level 1 page table index.

pub const fn p2_index(self) -> PageTableIndex[src]

Returns the 9-bit level 2 page table index.

pub const fn p3_index(self) -> PageTableIndex[src]

Returns the 9-bit level 3 page table index.

pub const fn p4_index(self) -> PageTableIndex[src]

Returns the 9-bit level 4 page table index.

Trait Implementations

impl Add<u64> for VirtAddr[src]

type Output = Self

The resulting type after applying the + operator.

fn add(self, rhs: u64) -> Self::Output[src]

Performs the + operation. Read more

impl Add<usize> for VirtAddr[src]

type Output = Self

The resulting type after applying the + operator.

fn add(self, rhs: usize) -> Self::Output[src]

Performs the + operation. Read more

impl AddAssign<u64> for VirtAddr[src]

fn add_assign(&mut self, rhs: u64)[src]

Performs the += operation. Read more

impl AddAssign<usize> for VirtAddr[src]

fn add_assign(&mut self, rhs: usize)[src]

Performs the += operation. Read more

impl Binary for VirtAddr[src]

fn fmt(&self, f: &mut Formatter<'_>) -> Result[src]

Formats the value using the given formatter.

impl Clone for VirtAddr[src]

fn clone(&self) -> VirtAddr[src]

Returns a copy of the value. Read more

fn clone_from(&mut self, source: &Self)1.0.0[src]

Performs copy-assignment from source. Read more

impl Debug for VirtAddr[src]

fn fmt(&self, f: &mut Formatter<'_>) -> Result[src]

Formats the value using the given formatter. Read more

impl LowerHex for VirtAddr[src]

fn fmt(&self, f: &mut Formatter<'_>) -> Result[src]

Formats the value using the given formatter.

impl Octal for VirtAddr[src]

fn fmt(&self, f: &mut Formatter<'_>) -> Result[src]

Formats the value using the given formatter.

impl Ord for VirtAddr[src]

fn cmp(&self, other: &VirtAddr) -> Ordering[src]

This method returns an Ordering between self and other. Read more

#[must_use]
fn max(self, other: Self) -> Self
1.21.0[src]

Compares and returns the maximum of two values. Read more

#[must_use]
fn min(self, other: Self) -> Self
1.21.0[src]

Compares and returns the minimum of two values. Read more

#[must_use]
fn clamp(self, min: Self, max: Self) -> Self
1.50.0[src]

Restrict a value to a certain interval. Read more

impl PartialEq<VirtAddr> for VirtAddr[src]

fn eq(&self, other: &VirtAddr) -> bool[src]

This method tests for self and other values to be equal, and is used by ==. Read more

fn ne(&self, other: &VirtAddr) -> bool[src]

This method tests for !=.

impl PartialOrd<VirtAddr> for VirtAddr[src]

fn partial_cmp(&self, other: &VirtAddr) -> Option<Ordering>[src]

This method returns an ordering between self and other values if one exists. Read more

#[must_use]
fn lt(&self, other: &Rhs) -> bool
1.0.0[src]

This method tests less than (for self and other) and is used by the < operator. Read more

#[must_use]
fn le(&self, other: &Rhs) -> bool
1.0.0[src]

This method tests less than or equal to (for self and other) and is used by the <= operator. Read more

#[must_use]
fn gt(&self, other: &Rhs) -> bool
1.0.0[src]

This method tests greater than (for self and other) and is used by the > operator. Read more

#[must_use]
fn ge(&self, other: &Rhs) -> bool
1.0.0[src]

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more

impl Pointer for VirtAddr[src]

fn fmt(&self, f: &mut Formatter<'_>) -> Result[src]

Formats the value using the given formatter.

impl Sub<VirtAddr> for VirtAddr[src]

type Output = u64

The resulting type after applying the - operator.

fn sub(self, rhs: VirtAddr) -> Self::Output[src]

Performs the - operation. Read more

impl Sub<u64> for VirtAddr[src]

type Output = Self

The resulting type after applying the - operator.

fn sub(self, rhs: u64) -> Self::Output[src]

Performs the - operation. Read more

impl Sub<usize> for VirtAddr[src]

type Output = Self

The resulting type after applying the - operator.

fn sub(self, rhs: usize) -> Self::Output[src]

Performs the - operation. Read more

impl SubAssign<u64> for VirtAddr[src]

fn sub_assign(&mut self, rhs: u64)[src]

Performs the -= operation. Read more

impl SubAssign<usize> for VirtAddr[src]

fn sub_assign(&mut self, rhs: usize)[src]

Performs the -= operation. Read more

impl UpperHex for VirtAddr[src]

fn fmt(&self, f: &mut Formatter<'_>) -> Result[src]

Formats the value using the given formatter.

impl Copy for VirtAddr[src]

impl Eq for VirtAddr[src]

impl StructuralEq for VirtAddr[src]

impl StructuralPartialEq for VirtAddr[src]

Auto Trait Implementations

impl Send for VirtAddr

impl Sync for VirtAddr

impl Unpin for VirtAddr

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

pub fn type_id(&self) -> TypeId[src]

Gets the TypeId of self. Read more

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

pub fn borrow(&self) -> &T[src]

Immutably borrows from an owned value. Read more

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

pub fn borrow_mut(&mut self) -> &mut T[src]

Mutably borrows from an owned value. Read more

impl<T> From<T> for T[src]

pub fn from(t: T) -> T[src]

Performs the conversion.

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

pub fn into(self) -> U[src]

Performs the conversion.

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

pub fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>[src]

Performs the conversion.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.

pub fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>[src]

Performs the conversion.