Skip to main content

unit_base

Function unit_base 

Source
pub fn unit_base(addr: u32, cap_start: u32) -> u32
Expand description

Identity of the read-only materialization unit containing addr: the cap ∩ cluster region, named by its base address max(cluster_lo, cap_start). The recompiler fault-arounds exactly the unit’s pages on its first touch (mapping them all read-only in one go), so a unit is mapped at most once — a pure fault-reduction key. It carries no gas: read-only page-in is charged eagerly at the CALL (crate::gas_const::call_frame_cost), not per touched unit.

A unit is keyed by both the cap (cap_start) and the 2 MiB cluster, so two distinct caps sharing a cluster are two units — a single fault/map event touches at most one DataCap. Because caps are disjoint, at most one cap per cluster starts at/below the cluster boundary (yielding unit_base == cluster_lo); every other cap in that cluster starts strictly later with a distinct cap_start, so this single max(cluster_lo, cap_start) value uniquely names one (cap, cluster) pair.