Wasmtime
memory.h File Reference
#include <wasm.h>
#include <wasmtime/error.h>
#include <wasmtime/extern.h>
#include <wasmtime/store.h>

Go to the source code of this file.

Functions

WASM_API_EXTERN wasmtime_error_twasmtime_memorytype_new (uint64_t min, bool max_present, uint64_t max, bool is_64, bool shared, uint8_t page_size_log2, wasm_memorytype_t **ret)
 Creates a new memory type from the specified parameters. More...
 
WASM_API_EXTERN uint64_t wasmtime_memorytype_minimum (const wasm_memorytype_t *ty)
 Returns the minimum size, in pages, of the specified memory type. More...
 
WASM_API_EXTERN bool wasmtime_memorytype_maximum (const wasm_memorytype_t *ty, uint64_t *max)
 Returns the maximum size, in pages, of the specified memory type. More...
 
WASM_API_EXTERN bool wasmtime_memorytype_is64 (const wasm_memorytype_t *ty)
 Returns whether this type of memory represents a 64-bit memory.
 
WASM_API_EXTERN bool wasmtime_memorytype_isshared (const wasm_memorytype_t *ty)
 Returns whether this type of memory represents a shared memory.
 
WASM_API_EXTERN uint64_t wasmtime_memorytype_page_size (const wasm_memorytype_t *ty)
 Returns the page size, in bytes, of this memory type.
 
WASM_API_EXTERN uint8_t wasmtime_memorytype_page_size_log2 (const wasm_memorytype_t *ty)
 Returns the log2 of this memory type's page size, in bytes.
 
WASM_API_EXTERN wasmtime_error_twasmtime_memory_new (wasmtime_context_t *store, const wasm_memorytype_t *ty, wasmtime_memory_t *ret)
 Creates a new WebAssembly linear memory. More...
 
WASM_API_EXTERN wasm_memorytype_twasmtime_memory_type (const wasmtime_context_t *store, const wasmtime_memory_t *memory)
 Returns the type of the memory specified.
 
WASM_API_EXTERN uint8_t * wasmtime_memory_data (const wasmtime_context_t *store, const wasmtime_memory_t *memory)
 Returns the base pointer in memory where the linear memory starts.
 
WASM_API_EXTERN size_t wasmtime_memory_data_size (const wasmtime_context_t *store, const wasmtime_memory_t *memory)
 Returns the byte length of this linear memory.
 
WASM_API_EXTERN uint64_t wasmtime_memory_size (const wasmtime_context_t *store, const wasmtime_memory_t *memory)
 Returns the length, in WebAssembly pages, of this linear memory.
 
WASM_API_EXTERN wasmtime_error_twasmtime_memory_grow (wasmtime_context_t *store, const wasmtime_memory_t *memory, uint64_t delta, uint64_t *prev_size)
 Attempts to grow the specified memory by delta pages. More...
 
WASM_API_EXTERN uint64_t wasmtime_memory_page_size (wasmtime_context_t *store, const wasmtime_memory_t *memory)
 Returns the size of a page, in bytes, for this memory. More...
 
WASM_API_EXTERN uint8_t wasmtime_memory_page_size_log2 (wasmtime_context_t *store, const wasmtime_memory_t *memory)
 Returns the log2 of this memory's page size, in bytes. More...
 

Detailed Description

Wasmtime API for interacting with wasm memories.

Function Documentation

◆ wasmtime_memory_grow()

WASM_API_EXTERN wasmtime_error_t * wasmtime_memory_grow ( wasmtime_context_t store,
const wasmtime_memory_t memory,
uint64_t  delta,
uint64_t *  prev_size 
)

Attempts to grow the specified memory by delta pages.

Parameters
storethe store that owns memory
memorythe memory to grow
deltathe number of pages to grow by
prev_sizewhere to store the previous size of memory

If memory cannot be grown then prev_size is left unchanged and an error is returned. Otherwise prev_size is set to the previous size of the memory, in WebAssembly pages, and NULL is returned.

◆ wasmtime_memory_new()

WASM_API_EXTERN wasmtime_error_t * wasmtime_memory_new ( wasmtime_context_t store,
const wasm_memorytype_t ty,
wasmtime_memory_t ret 
)

Creates a new WebAssembly linear memory.

Parameters
storethe store to create the memory within
tythe type of the memory to create
retwhere to store the returned memory

If an error happens when creating the memory it's returned and owned by the caller. If an error happens then ret is not filled in.

◆ wasmtime_memory_page_size()

WASM_API_EXTERN uint64_t wasmtime_memory_page_size ( wasmtime_context_t store,
const wasmtime_memory_t memory 
)

Returns the size of a page, in bytes, for this memory.

Parameters
storethe store that owns memory
memorythe memory to get the page size of

WebAssembly memories are made up of a whole number of pages, so the byte size (as returned by wasmtime_memory_data_size) will always be a multiple of their page size. Different Wasm memories may have different page sizes.

By default this is 64KiB (aka 0x10000, 2**16, 1<<16, or 65536) but the custom-page-sizes proposal allows opting into a page size of 1. Future extensions might allow any power of two as a page size.

◆ wasmtime_memory_page_size_log2()

WASM_API_EXTERN uint8_t wasmtime_memory_page_size_log2 ( wasmtime_context_t store,
const wasmtime_memory_t memory 
)

Returns the log2 of this memory's page size, in bytes.

Parameters
storethe store that owns memory
memorythe memory to get the page size of

WebAssembly memories are made up of a whole number of pages, so the byte size (as returned by wasmtime_memory_data_size) will always be a multiple of their page size. Different Wasm memories may have different page sizes.

By default the page size is 64KiB (aka 0x10000, 2**16, 1<<16, or 65536) but the custom-page-sizes proposal allows opting into a page size of 1. Future extensions might allow any power of two as a page size.

◆ wasmtime_memorytype_maximum()

WASM_API_EXTERN bool wasmtime_memorytype_maximum ( const wasm_memorytype_t ty,
uint64_t *  max 
)

Returns the maximum size, in pages, of the specified memory type.

If this memory type doesn't have a maximum size listed then false is returned. Otherwise true is returned and the max pointer is filled in with the specified maximum size, in pages.

Note that this function is preferred over wasm_memorytype_limits for compatibility with the memory64 proposal.

◆ wasmtime_memorytype_minimum()

WASM_API_EXTERN uint64_t wasmtime_memorytype_minimum ( const wasm_memorytype_t ty)

Returns the minimum size, in pages, of the specified memory type.

Note that this function is preferred over wasm_memorytype_limits for compatibility with the memory64 proposal.

◆ wasmtime_memorytype_new()

WASM_API_EXTERN wasmtime_error_t * wasmtime_memorytype_new ( uint64_t  min,
bool  max_present,
uint64_t  max,
bool  is_64,
bool  shared,
uint8_t  page_size_log2,
wasm_memorytype_t **  ret 
)

Creates a new memory type from the specified parameters.

Note that this function is preferred over wasm_memorytype_new for compatibility with the memory64 proposal.