#[repr(transparent)]pub struct VirtualAddress {
pub addr: usize,
}Expand description
A virtual memory address.
Fields§
§addr: usizeThe underlying address
Implementations§
Source§impl VirtualAddress
impl VirtualAddress
Sourcepub const fn new(addr: usize) -> Self
pub const fn new(addr: usize) -> Self
Creates a new VirtualAddress with the given address.
§Examples
use kernel_api::memory::VirtualAddress;
let addr = VirtualAddress::new(0);Sourcepub const fn as_ptr(self) -> *mut u8
pub const fn as_ptr(self) -> *mut u8
Converts a VirtualAddress into a raw pointer.
§Examples
use kernel_api::memory::VirtualAddress;
let addr = VirtualAddress::new(0x1000);
let ptr = addr.as_ptr();
// if `addr` came from allocated memory, it can be accessed through `ptr`
// unsafe { *ptr = 5 };Sourcepub const fn is_higher_half(self) -> bool
pub const fn is_higher_half(self) -> bool
Returns true if the address is in the upper half of the address space, i.e. kernelspace.
§Examples
use kernel_api::memory::VirtualAddress;
let addr = VirtualAddress::new(usize::MAX);
assert_eq!(addr.is_higher_half(), true);Sourcepub const fn align_down_to_page(self) -> RawPage
pub const fn align_down_to_page(self) -> RawPage
Returns the closest RawPage at or below the current address.
§Examples
use kernel_api::memory::{VirtualAddress, PAGE_SIZE};
let address = VirtualAddress::new(0x1);
let page = address.align_down_to_page();
assert!(address >= *page);
assert!((*page).is_aligned_to(PAGE_SIZE));
// If the address is already aligned, then the value will remain unchanged.
let address = VirtualAddress::new(PAGE_SIZE);
let page = address.align_down_to_page();
assert!(address == *page);Sourcepub const fn align_up_to_page(self) -> RawPage
pub const fn align_up_to_page(self) -> RawPage
Returns the closest RawPage at or above the current address.
§Examples
use kernel_api::memory::{VirtualAddress, PAGE_SIZE};
let address = VirtualAddress::new(0x1);
let page = address.align_up_to_page();
assert!(address <= *page);
assert!((*page).is_aligned_to(PAGE_SIZE));
// If the address is already aligned, then the value will remain unchanged.
let address = VirtualAddress::new(PAGE_SIZE);
let page = address.align_up_to_page();
assert!(address == *page);Sourcepub const fn is_aligned_to(self, align: usize) -> bool
pub const fn is_aligned_to(self, align: usize) -> bool
Sourcepub const fn saturating_add(self, rhs: usize) -> Self
pub const fn saturating_add(self, rhs: usize) -> Self
Computes self + rhs, saturating when the address reaches [usize::MAX].
§Examples
use kernel_api::memory::VirtualAddress;
let a = VirtualAddress::new(0x1000);
assert_eq!(a.saturating_add(1), Some(VirtualAddress::new(0x1001)));
assert_eq!(a.saturating_add(usize::MAX), None);Sourcepub const fn saturating_sub(self, rhs: usize) -> Self
pub const fn saturating_sub(self, rhs: usize) -> Self
Computes self - rhs saturating when the address reaches 0.
§Examples
use kernel_api::memory::VirtualAddress;
let a = VirtualAddress::new(0x1001);
assert_eq!(a.saturating_sub(1), Some(VirtualAddress::new(0x1000)));
assert_eq!(a.saturating_sub(usize::MAX), None);Sourcepub const fn to_physical(self) -> PhysicalAddress
pub const fn to_physical(self) -> PhysicalAddress
Converts an address in the physical page map region into an PhysicalAddress.
This is the virtual-to-physical counterpart to to_virtual().
§Panics
Panics if the address is not in the physical page map region on a best effort basis.
§Examples
ⓘ
use kernel_api::memory::VirtualAddress;
let virt = VirtualAddress::new(0);
// converting non physical page map addresses may panic
let phys = virt.to_physical();Trait Implementations§
Source§impl Add<isize> for VirtualAddress
impl Add<isize> for VirtualAddress
Source§impl Add<usize> for VirtualAddress
impl Add<usize> for VirtualAddress
Source§impl Clone for VirtualAddress
impl Clone for VirtualAddress
Source§fn clone(&self) -> VirtualAddress
fn clone(&self) -> VirtualAddress
Returns a duplicate of the value. Read more
1.0.0 (const: unstable)§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreimpl Copy for VirtualAddress
Source§impl Debug for VirtualAddress
impl Debug for VirtualAddress
impl Eq for VirtualAddress
Source§impl<T: ?Sized> From<*const T> for VirtualAddress
impl<T: ?Sized> From<*const T> for VirtualAddress
Source§impl<T: ?Sized> From<*mut T> for VirtualAddress
impl<T: ?Sized> From<*mut T> for VirtualAddress
Source§impl From<RawPage> for VirtualAddress
impl From<RawPage> for VirtualAddress
Source§impl Hash for VirtualAddress
impl Hash for VirtualAddress
Source§impl LowerHex for VirtualAddress
impl LowerHex for VirtualAddress
Source§impl Ord for VirtualAddress
impl Ord for VirtualAddress
Source§fn cmp(&self, other: &VirtualAddress) -> Ordering
fn cmp(&self, other: &VirtualAddress) -> Ordering
1.21.0 (const: unstable)§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
Compares and returns the maximum of two values. Read more
1.21.0 (const: unstable)§fn min(self, other: Self) -> Selfwhere
Self: Sized,
fn min(self, other: Self) -> Selfwhere
Self: Sized,
Compares and returns the minimum of two values. Read more
Source§impl PartialEq for VirtualAddress
impl PartialEq for VirtualAddress
Source§impl PartialOrd for VirtualAddress
impl PartialOrd for VirtualAddress
Source§impl Step for VirtualAddress
impl Step for VirtualAddress
Source§fn steps_between(start: &Self, end: &Self) -> (usize, Option<usize>)
fn steps_between(start: &Self, end: &Self) -> (usize, Option<usize>)
🔬This is a nightly-only experimental API. (
step_trait)Returns the bounds on the number of successor steps required to get from
start to end
like [Iterator::size_hint()][Iterator::size_hint()]. Read moreSource§fn forward_checked(start: Self, count: usize) -> Option<Self>
fn forward_checked(start: Self, count: usize) -> Option<Self>
🔬This is a nightly-only experimental API. (
step_trait)Source§fn forward_overflowing(start: Self, count: usize) -> (Self, bool)
fn forward_overflowing(start: Self, count: usize) -> (Self, bool)
🔬This is a nightly-only experimental API. (
step_trait)Returns the value that would be obtained by taking the successor
of
self count times along with a boolean tracking whether overflow
occurred. Read moreSource§fn backward_checked(start: Self, count: usize) -> Option<Self>
fn backward_checked(start: Self, count: usize) -> Option<Self>
🔬This is a nightly-only experimental API. (
step_trait)Source§fn backward_overflowing(start: Self, count: usize) -> (Self, bool)
fn backward_overflowing(start: Self, count: usize) -> (Self, bool)
🔬This is a nightly-only experimental API. (
step_trait)Returns the value that would be obtained by taking the successor
of
self count times along with a boolean tracking whether overflow
occurred. Read more§fn forward(start: Self, count: usize) -> Self
fn forward(start: Self, count: usize) -> Self
🔬This is a nightly-only experimental API. (
step_trait)§unsafe fn forward_unchecked(start: Self, count: usize) -> Self
unsafe fn forward_unchecked(start: Self, count: usize) -> Self
🔬This is a nightly-only experimental API. (
step_trait)§fn backward(start: Self, count: usize) -> Self
fn backward(start: Self, count: usize) -> Self
🔬This is a nightly-only experimental API. (
step_trait)§unsafe fn backward_unchecked(start: Self, count: usize) -> Self
unsafe fn backward_unchecked(start: Self, count: usize) -> Self
🔬This is a nightly-only experimental API. (
step_trait)impl StructuralPartialEq for VirtualAddress
Source§impl Sub for VirtualAddress
Returns the number of bytes between self and rhs.
impl Sub for VirtualAddress
Returns the number of bytes between self and rhs.
Source§impl Sub<isize> for VirtualAddress
impl Sub<isize> for VirtualAddress
Auto Trait Implementations§
impl Freeze for VirtualAddress
impl RefUnwindSafe for VirtualAddress
impl Send for VirtualAddress
impl Sync for VirtualAddress
impl Unpin for VirtualAddress
impl UnsafeUnpin for VirtualAddress
impl UnwindSafe for VirtualAddress
Blanket Implementations§
§impl<T> Any for Twhere
T: 'static + ?Sized,
impl<T> Any for Twhere
T: 'static + ?Sized,
§impl<T> Borrow<T> for Twhere
T: ?Sized,
impl<T> Borrow<T> for Twhere
T: ?Sized,
§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§unsafe fn clone_to_uninit(&self, dest: *mut u8)
unsafe fn clone_to_uninit(&self, dest: *mut u8)
🔬This is a nightly-only experimental API. (
clone_to_uninit)§impl<Q, K> Equivalent<K> for Qwhere
Q: Eq + ?Sized,
K: Borrow<Q> + ?Sized,
impl<Q, K> Equivalent<K> for Qwhere
Q: Eq + ?Sized,
K: Borrow<Q> + ?Sized,
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
Checks if this value is equivalent to the given key. Read more