Skip to main content

Crate ax_memory_addr

Crate ax_memory_addr 

Source
Expand description

ax-memory-addr

Wrappers and helper functions for physical and virtual addresses

Crates.io Docs.rs Rust License

English | 中文

§Introduction

ax-memory-addr provides Wrappers and helper functions for physical and virtual addresses. It is maintained as part of the TGOSKits component set and is intended for Rust projects that integrate with ArceOS, AxVisor, or related low-level systems software.

ax-memory-addr was derived from https://github.com/arceos-org/axmm_crates

§Quick Start

§Installation

Add this crate to your Cargo.toml:

[dependencies]
ax-memory-addr = "0.6.1"

§Run Check and Test

# Enter the crate directory
cd components/axmm_crates/memory_addr

# Format code
cargo fmt --all

# Run clippy
cargo clippy --all-targets --all-features

# Run tests
cargo test --all-features

# Build documentation
cargo doc --no-deps

§Integration

§Example

use ax_memory_addr as _;

fn main() {
    // Integrate `ax-memory-addr` into your project here.
}

§Documentation

Generate and view API documentation:

cargo doc --no-deps --open

Online documentation: docs.rs/ax-memory-addr

§Contributing

  1. Fork the repository and create a branch
  2. Run local format and checks
  3. Run local tests relevant to this crate
  4. Submit a PR and ensure CI passes

§License

Licensed under the Apache License, Version 2.0. See LICENSE for details.

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.
DynPageIter
A page-by-page iterator with dynamic page size.
PageIter
A page-by-page iterator.
PhysAddr
A physical memory address.
VirtAddr
A virtual memory address.

Constants§

PAGE_SIZE_1G
The size of a 1G page (1073741824 bytes).
PAGE_SIZE_2M
The size of a 2M page (2097152 bytes).
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§

PageIter1G
A PageIter for 1G pages.
PageIter2M
A PageIter for 2M pages.
PageIter4K
A PageIter for 4K pages.
PhysAddrRange
A range of physical addresses PhysAddr.
VirtAddrRange
A range of virtual addresses VirtAddr.