pub struct WasmMemory {
pub index: u32,
pub initial_pages: u32,
pub max_pages: Option<u32>,
pub shared: bool,
pub memory64: bool,
pub page_size_log2: Option<u32>,
}Expand description
WASM linear memory specification
Fields§
§index: u32Memory index
initial_pages: u32Initial size in pages (64KB each)
max_pages: Option<u32>Maximum size in pages (if specified)
Whether memory is shared (requires threads proposal)
memory64: bool#1209: whether this memory is 64-bit-INDEXED (the memory64 proposal,
(memory i64 ...)) rather than the default 32-bit index type. No
codegen path in this crate handles an i64 memory index — data-segment
offsets are decoded i32.const-only (silently DROPPING an
i64.const-offset segment) and every address-materialization path
assumes a 32-bit address, so a memory64 module compiled today produces
EXECUTABLE, WRONG code rather than failing to compile. This flag is
consumed by refuse_memory64_module in synth-cli to turn that into a
loud decline at decode time, the #1046 pattern.
page_size_log2: Option<u32>#1315: the log2 of this memory’s DECLARED page size (the
custom-page-sizes proposal, (memory 1 1 (pagesize N))), or None for
the default 64 KiB page. wasmparser decodes it; nothing in this
workspace read it, so a memory declared one byte long was reported and
reserved as 65536 — and __synth_mem_size_N, which the embedder
programs one MPU region from (#1145), inherited the over-grant by the
page-size ratio. Consumed by refuse_custom_page_size in synth-cli,
the refuse_memory64_module (#1209) pattern: decode the declaration,
then decline loudly rather than silently ignore it.
Implementations§
Source§impl WasmMemory
impl WasmMemory
Sourcepub fn page_bytes(&self) -> u32
pub fn page_bytes(&self) -> u32
#1441: this memory’s DECLARED page size in bytes.
The custom-page-sizes proposal permits EXACTLY two values — the vendored
custom-page-sizes-invalid.wast asserts (pagesize 32) invalid BY NAME
under its own “Power-of-two page sizes that are not 1 or 64KiB” heading —
so on any module that validates page_size_log2 is 0 or 16.
checked_shl rather than <<, and this is deliberate rather than
defensive habit: synth-core is a PUBLISHED library and gale asked on
#1145 that the refusal NOT be relocated into it (“refusing in the library
closes a door gale wants open”; v0.81 built that relocation anyway and
reverted it). So a library caller can hand this a malformed log2 that
no CLI refusal has seen, and 1u32 << 40 is a debug panic and a release
wrap. A getter must be TOTAL.
Sourcepub fn initial_bytes(&self) -> u32
pub fn initial_bytes(&self) -> u32
Get initial size in bytes.
TWIN with Self::max_bytes (#1441): both read page_bytes() and both
saturate. They are listed together because fixing one and not the other
is this repo’s recorded twin shape — v0.70 narrowed the integer allocator
check and v0.71 found its VFP twin still wrong — and because a memory
whose INITIAL honours the declaration while its MAX does not reserves the
over-granted extent anyway, which is #1315’s silent over-grant wearing
the fix’s clothes.
Sourcepub fn max_bytes(&self) -> u32
pub fn max_bytes(&self) -> u32
Get maximum size in bytes (or initial if not specified).
TWIN with Self::initial_bytes — see the note there.