javm_transpiler/layout.rs
1//! Cap-index convention for transpiler-emitted Images.
2//!
3//! The *geometry* of a linked program — which data regions exist, how
4//! many pages each occupies, and where they land in the guest address
5//! space — belongs to [`nub_program::Regions`] and is decided by the
6//! linker. What lives here is the one thing that is genuinely a JAVM
7//! choice: which cnode slot each region's `Cap::Data` is filed under.
8//!
9//! Slots 65..68 are arbitrary but fixed. They sit above the low slots a
10//! guest's own cnode uses, and the runtime resolves each Image
11//! `MemoryMapping`'s `source` path through them.
12
13use nub_program::RegionKind;
14
15/// Cap index of the stack DATA cap.
16pub const STACK_CAP_INDEX: u8 = 65;
17/// Cap index of the read-only DATA cap (`.rodata`).
18pub const RO_CAP_INDEX: u8 = 66;
19/// Cap index of the read-write DATA cap (`.data` + `.bss`).
20pub const RW_CAP_INDEX: u8 = 67;
21/// Cap index of the heap DATA cap.
22pub const HEAP_CAP_INDEX: u8 = 68;
23
24/// Re-exported PVM2 ABI layout constants (see [`nub_program::abi`]).
25pub use javm_cap::layout::{CODE_BASE, DATA_BASE, MAX_CODE_SIZE};
26/// PVM page size in bytes.
27pub use nub_program::abi::PAGE_SIZE as PVM_PAGE_SIZE;
28
29/// The cnode slot a region's `Cap::Data` is filed under.
30pub const fn cap_index(kind: RegionKind) -> u8 {
31 match kind {
32 RegionKind::Stack => STACK_CAP_INDEX,
33 RegionKind::Ro => RO_CAP_INDEX,
34 RegionKind::Rw => RW_CAP_INDEX,
35 RegionKind::Heap => HEAP_CAP_INDEX,
36 }
37}