6 releases

0.3.1 Sep 14, 2024
0.3.0 Aug 27, 2024
0.2.1 Jul 28, 2024
0.1.1 Jul 11, 2024
0.1.0 May 9, 2023

#101 in Operating systems

Download history 451/week @ 2024-08-16 528/week @ 2024-08-23 756/week @ 2024-08-30 914/week @ 2024-09-06 542/week @ 2024-09-13 438/week @ 2024-09-20 253/week @ 2024-09-27 682/week @ 2024-10-04 1636/week @ 2024-10-11 1630/week @ 2024-10-18 813/week @ 2024-10-25 244/week @ 2024-11-01 411/week @ 2024-11-08 688/week @ 2024-11-15 828/week @ 2024-11-22 587/week @ 2024-11-29

2,546 downloads per month
Used in 10 crates (7 directly)

GPL-3.0-or-later OR Apache-2…

49KB
811 lines

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

No runtime deps