Struct wasmtime_environ::ModuleTranslation

source ·
pub struct ModuleTranslation<'data> {
    pub module: Module,
    pub wasm: &'data [u8],
    pub function_body_inputs: PrimaryMap<DefinedFuncIndex, FunctionBodyData<'data>>,
    pub exported_signatures: Vec<SignatureIndex>,
    pub debuginfo: DebugInfoData<'data>,
    pub has_unparsed_debuginfo: bool,
    pub data: Vec<Cow<'data, [u8]>>,
    pub data_align: Option<u64>,
    pub passive_data: Vec<&'data [u8]>,
    /* private fields */
}
Expand description

The result of translating via ModuleEnvironment. Function bodies are not yet translated, and data initializers have not yet been copied out of the original buffer.

Fields§

§module: Module

Module information.

§wasm: &'data [u8]

The input wasm binary.

This can be useful, for example, when modules are parsed from a component and the embedder wants access to the raw wasm modules themselves.

§function_body_inputs: PrimaryMap<DefinedFuncIndex, FunctionBodyData<'data>>

References to the function bodies.

§exported_signatures: Vec<SignatureIndex>

A list of type signatures which are considered exported from this module, or those that can possibly be called. This list is sorted, and trampolines for each of these signatures are required.

§debuginfo: DebugInfoData<'data>

DWARF debug information, if enabled, parsed from the module.

§has_unparsed_debuginfo: bool

Set if debuginfo was found but it was not parsed due to Tunables configuration.

§data: Vec<Cow<'data, [u8]>>

List of data segments found in this module which should be concatenated together for the final compiled artifact.

These data segments, when concatenated, are indexed by the MemoryInitializer type.

§data_align: Option<u64>

The desired alignment of data in the final data section of the object file that we’ll emit.

Note that this is 1 by default but MemoryInitialization::Static might switch this to a higher alignment to facilitate mmap-ing data from an object file into a linear memory.

§passive_data: Vec<&'data [u8]>

List of passive element segments found in this module which will get concatenated for the final artifact.

Implementations§

source§

impl ModuleTranslation<'_>

source

pub fn try_static_init( &mut self, page_size: u64, max_image_size_always_allowed: u64, )

Attempts to convert segmented memory initialization into static initialization for the module that this translation represents.

If this module’s memory initialization is not compatible with paged initialization then this won’t change anything. Otherwise if it is compatible then the memory_initialization field will be updated.

Takes a page_size argument in order to ensure that all initialization is page-aligned for mmap-ability, and max_image_size_always_allowed to control how we decide whether to use static init.

We will try to avoid generating very sparse images, which are possible if e.g. a module has an initializer at offset 0 and a very high offset (say, 1 GiB). To avoid this, we use a dual condition: we always allow images less than max_image_size_always_allowed, and the embedder of Wasmtime can set this if desired to ensure that static init should always be done if the size of the module or its heaps is otherwise bounded by the system. We also allow images with static init data bigger than that, but only if it is “dense”, defined as having at least half (50%) of its pages with some data.

We could do something slightly better by building a dense part and keeping a sparse list of outlier/leftover segments (see issue #3820). This would also allow mostly-static init of modules that have some dynamically-placed data segments. But, for now, this is sufficient to allow a system that “knows what it’s doing” to always get static init.

source

pub fn try_func_table_init(&mut self)

Attempts to convert the module’s table initializers to FuncTable form where possible. This enables lazy table initialization later by providing a one-to-one map of initial table values, without having to parse all segments.

source§

impl<'data> ModuleTranslation<'data>

source

pub fn get_types(&self) -> &Types

Returns a reference to the type information of the current module.

Trait Implementations§

source§

impl<'data> Default for ModuleTranslation<'data>

source§

fn default() -> ModuleTranslation<'data>

Returns the “default value” for a type. Read more

Auto Trait Implementations§

§

impl<'data> !Freeze for ModuleTranslation<'data>

§

impl<'data> RefUnwindSafe for ModuleTranslation<'data>

§

impl<'data> Send for ModuleTranslation<'data>

§

impl<'data> Sync for ModuleTranslation<'data>

§

impl<'data> Unpin for ModuleTranslation<'data>

§

impl<'data> UnwindSafe for ModuleTranslation<'data>

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> 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, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

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

§

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.