Wasmtime
module.h File Reference
#include <wasm.h>
#include <wasmtime/error.h>

Go to the source code of this file.

Typedefs

typedef struct wasmtime_module wasmtime_module_t
 Convenience alias for wasmtime_module.
 

Functions

wasmtime_error_twasmtime_module_new (wasm_engine_t *engine, const uint8_t *wasm, size_t wasm_len, wasmtime_module_t **ret)
 Compiles a WebAssembly binary into a wasmtime_module_t. More...
 
void wasmtime_module_delete (wasmtime_module_t *m)
 Deletes a module.
 
wasmtime_module_twasmtime_module_clone (wasmtime_module_t *m)
 Creates a shallow clone of the specified module, increasing the internal reference count.
 
void wasmtime_module_imports (const wasmtime_module_t *module, wasm_importtype_vec_t *out)
 Same as wasm_module_imports, but for wasmtime_module_t.
 
void wasmtime_module_exports (const wasmtime_module_t *module, wasm_exporttype_vec_t *out)
 Same as wasm_module_exports, but for wasmtime_module_t.
 
wasmtime_error_twasmtime_module_validate (wasm_engine_t *engine, const uint8_t *wasm, size_t wasm_len)
 Validate a WebAssembly binary. More...
 
wasmtime_error_twasmtime_module_serialize (wasmtime_module_t *module, wasm_byte_vec_t *ret)
 This function serializes compiled module artifacts as blob data. More...
 
wasmtime_error_twasmtime_module_deserialize (wasm_engine_t *engine, const uint8_t *bytes, size_t bytes_len, wasmtime_module_t **ret)
 Build a module from serialized data. More...
 
wasmtime_error_twasmtime_module_deserialize_file (wasm_engine_t *engine, const char *path, wasmtime_module_t **ret)
 Deserialize a module from an on-disk file. More...
 

Detailed Description

APIs for interacting with modules in Wasmtime

Function Documentation

◆ wasmtime_module_deserialize()

wasmtime_error_t * wasmtime_module_deserialize ( wasm_engine_t engine,
const uint8_t *  bytes,
size_t  bytes_len,
wasmtime_module_t **  ret 
)

Build a module from serialized data.

This function does not take ownership of any of its arguments, but the returned error and module are owned by the caller.

This function is not safe to receive arbitrary user input. See the Rust documentation for more information on what inputs are safe to pass in here (e.g. only that of wasmtime_module_serialize)

◆ wasmtime_module_deserialize_file()

wasmtime_error_t * wasmtime_module_deserialize_file ( wasm_engine_t engine,
const char *  path,
wasmtime_module_t **  ret 
)

Deserialize a module from an on-disk file.

This function is the same as wasmtime_module_deserialize except that it reads the data for the serialized module from the path on disk. This can be faster than the alternative which may require copying the data around.

This function does not take ownership of any of its arguments, but the returned error and module are owned by the caller.

This function is not safe to receive arbitrary user input. See the Rust documentation for more information on what inputs are safe to pass in here (e.g. only that of wasmtime_module_serialize)

◆ wasmtime_module_new()

wasmtime_error_t * wasmtime_module_new ( wasm_engine_t engine,
const uint8_t *  wasm,
size_t  wasm_len,
wasmtime_module_t **  ret 
)

Compiles a WebAssembly binary into a wasmtime_module_t.

This function will compile a WebAssembly binary into an owned wasm_module_t. This performs the same as wasm_module_new except that it returns a wasmtime_error_t type to get richer error information.

On success the returned wasmtime_error_t is NULL and the ret pointer is filled in with a wasm_module_t. On failure the wasmtime_error_t is non-NULL and the ret pointer is unmodified.

This function does not take ownership of any of its arguments, but the returned error and module are owned by the caller.

◆ wasmtime_module_serialize()

wasmtime_error_t * wasmtime_module_serialize ( wasmtime_module_t module,
wasm_byte_vec_t ret 
)

This function serializes compiled module artifacts as blob data.

Parameters
modulethe module
retif the conversion is successful, this byte vector is filled in with the serialized compiled module.
Returns
a non-null error if parsing fails, or returns NULL. If parsing fails then ret isn't touched.

This function does not take ownership of module, and the caller is expected to deallocate the returned wasmtime_error_t and wasm_byte_vec_t.

◆ wasmtime_module_validate()

wasmtime_error_t * wasmtime_module_validate ( wasm_engine_t engine,
const uint8_t *  wasm,
size_t  wasm_len 
)

Validate a WebAssembly binary.

This function will validate the provided byte sequence to determine if it is a valid WebAssembly binary within the context of the engine provided.

This function does not take ownership of its arguments but the caller is expected to deallocate the returned error if it is non-NULL.

If the binary validates then NULL is returned, otherwise the error returned describes why the binary did not validate.