crates

address_space_layout

check proofs license minimum Rust version

Which band of a process's low half holds what. Eight bands tile the first 2 GiB, the same on aarch64, riscv64 and x86_64, and const fn checks stop the build when a page or a window lies outside its band.

Several programs must agree on where things go in a process: a linker script, two loaders, a runtime, a kernel and every fixture that shares a page. This crate is the one table they read, so the table places a new page, not a number chosen beside the others. The crate is no_std, has no dependencies and is dual licensed MIT OR Apache-2.0. Kani proves it: every property it claims is a harness in the tree, and every harness carries a falsification patch that shows what turns it red.

EXAMPLES

Place a pair page and a whole window in a const, so a wrong address stops the build.

use address_space_layout::{pair_page, window, SERVICE_WINDOWS};

// One page of a builder's shared window, checked against PAIR_PAGES.
const CONTROL_PAGE: u64 = pair_page(0x60_0000);
// An 8 MiB block channel: all of it, not only its first page, lies in SERVICE_WINDOWS.
const BLOCK_CHANNEL: u64 = window(SERVICE_WINDOWS, 0x5000_0000, 8 << 20);

assert_eq!(CONTROL_PAGE, 0x60_0000);
assert_eq!(BLOCK_CHANNEL, 0x5000_0000);

Build a band of your own with Band::new, which stops the build when it is empty, inverted or not page aligned.

use address_space_layout::Band;

const SCRATCH: Band = Band::new(0x10_0000, 0x20_0000);
assert_eq!(SCRATCH.bytes(), 0x10_0000);

Ask whether a program image fits, and print why it does not.

use address_space_layout::{check_image, IMAGE};

assert!(check_image(IMAGE.start, IMAGE.start + 0x29_c000).is_ok());
let refusal = check_image(IMAGE.start, IMAGE.end + 0x1000).unwrap_err();
println!("{refusal}");
// the program image is too large: it ends at 0x7f001000, past the stack's base at 0x7f000000;
// an image may be at most 496 MiB

What is proven

Eleven Kani harnesses state the layout per address and per window:

Each harness has a falsification record at falsifications/verification.<harness>.patch, where verification is the module that holds the harnesses. Applying one makes its harness fail at its own assertion, which shows the proof checks something. From the crate root of a git checkout:

git apply -p1 falsifications/verification.pair_page_accepts_every_page_of_its_band.patch
cargo kani --harness verification::pair_page_accepts_every_page_of_its_band --exact
git checkout -- src

The second command is the expected red. It names the failed check, here a window must lie wholly inside its band, and ends with VERIFICATION:- FAILED and a summary of 0 verified harnesses and 1 failure. The third command reverts the patch; revert each one before the next.

Not proven: that two windows in one band do not overlap. The crate that places them asserts that.

The bands

band start end size what goes in it
NULL_GUARD 0x0000_0000 0x0020_0000 2 MiB nothing, ever
PAIR_PAGES 0x0020_0000 0x1000_0000 254 MiB pages one builder agrees with the one program it builds, and a program's private windows
RUNTIME_WINDOWS 0x1000_0000 0x4000_0000 768 MiB windows a loader or runtime places for a program
HEAP 0x4000_0000 0x5000_0000 256 MiB the heap and nothing else
SERVICE_WINDOWS 0x5000_0000 0x6000_0000 256 MiB large windows a service contract names
IMAGE 0x6000_0000 0x7F00_0000 496 MiB the program's code and data
STACK 0x7F00_0000 0x7FFF_0000 16 MiB less 64 KiB the stack, growing down; its lowest page is never mapped
PROCESS_PAGES 0x7FFF_0000 0x8000_0000 64 KiB pages the kernel maps into every process unasked

The crate's root documentation, which cargo doc --open shows, holds the same table, the order in which to ask where a new page goes, and the reasons for the numbers.

Build, test and prove

You need a Rust toolchain at or above the minimum version at the foot of this page (rustup is the usual way to get one) and a git checkout. From the crate root:

BUGS

Minimum Rust version

Rust 1.88. To check it, run rustup toolchain install 1.88, then cargo +1.88 build and cargo +1.88 test. The weekly msrv job in CI runs the same build and tests at that version.

License

MIT OR Apache-2.0, at your option: see LICENSE-MIT and LICENSE-APACHE.