Skip to main content

WasmMemory

Struct WasmMemory 

Source
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: u32

Memory index

§initial_pages: u32

Initial size in pages (64KB each)

§max_pages: Option<u32>

Maximum size in pages (if specified)

§shared: bool

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

Source

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.

Source

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.

Source

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.

Trait Implementations§

Source§

impl Clone for WasmMemory

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for WasmMemory

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.