Crate memory_addr

Source
Expand description

§memory_addr

Crates.io Docs.rs CI

Wrappers and helper functions for physical and virtual memory addresses.

§Examples

use memory_addr::{pa, va, va_range, PhysAddr, VirtAddr, MemoryAddr};

let phys_addr = PhysAddr::from(0x12345678);
let virt_addr = VirtAddr::from(0x87654321);

assert_eq!(phys_addr.align_down(0x1000usize), pa!(0x12345000));
assert_eq!(phys_addr.align_offset_4k(), 0x678);
assert_eq!(virt_addr.align_up_4k(), va!(0x87655000));
assert!(!virt_addr.is_aligned_4k());
assert!(va!(0xabcedf0).is_aligned(16usize));

let va_range = va_range!(0x87654000..0x87655000);
assert_eq!(va_range.start, va!(0x87654000));
assert_eq!(va_range.size(), 0x1000);
assert!(va_range.contains(virt_addr));
assert!(va_range.contains_range(va_range!(virt_addr..virt_addr + 0x100)));
assert!(!va_range.contains_range(va_range!(virt_addr..virt_addr + 0x1000)));

Macros§

addr_range
Converts the given range expression into AddrRange. Panics if the range is invalid.
def_usize_addr
Creates a new address type by wrapping an usize.
def_usize_addr_formatter
Creates implementations for the Debug, LowerHex, and UpperHex traits for the given address types defined by the def_usize_addr.
pa
Alias for PhysAddr::from_usize.
pa_range
Converts the given range expression into PhysAddrRange. Panics if the range is invalid.
va
Alias for VirtAddr::from_usize.
va_range
Converts the given range expression into VirtAddrRange. Panics if the range is invalid.

Structs§

AddrRange
A range of a given memory address type A.
PageIter
A page-by-page iterator.
PhysAddr
A physical memory address.
VirtAddr
A virtual memory address.

Constants§

PAGE_SIZE_4K
The size of a 4K page (4096 bytes).

Traits§

MemoryAddr
A trait for memory address types.

Functions§

align_down
Align address downwards.
align_down_4k
Align address downwards to 4096 (bytes).
align_offset
Returns the offset of the address within the alignment.
align_offset_4k
Returns the offset of the address within a 4K-sized page.
align_up
Align address upwards.
align_up_4k
Align address upwards to 4096 (bytes).
is_aligned
Checks whether the address has the demanded alignment.
is_aligned_4k
Checks whether the address is 4K-aligned.

Type Aliases§

PageIter4K
A PageIter for 4K pages.
PhysAddrRange
A range of physical addresses PhysAddr.
VirtAddrRange
A range of virtual addresses VirtAddr.